PDA

View Full Version : Simple PHP Email question


adamcasey
02-07-2008, 09:01 AM
I've just created a web form and it's now working perfectly.
However I want to add the ability to email it to more than one recipient and was wondering how to do this as I had no knowledge of PHP until yesterday.

Actionscript:

var senderLoad:LoadVars = new LoadVars();
var receiveLoad:LoadVars = new LoadVars();

sendBU.onRelease = function() {
senderLoad.nameInput = nameInput.text;
senderLoad.emailInput = emailInput.text;
senderLoad.companyInput = companyInput.text;
senderLoad.contacttelInput = contacttelInput.text;
senderLoad.countyCOMBO = countyCOMBO.ComboBox.text;
senderLoad.sendAndLoad("http://www.tees.me.uk/Book/send.php",receiveLoad);
}




PHP:

<?PHP
$to = "[email protected]";
$cc = "[email protected]"; - I thought this might work but it didn't
$subject = "Online Flip Book Demo Request";
$message = "Name: " . $nameInput;
$message .= "\nEmail: " . $emailInput;
$message .= "\nCompany: " . $companyInput;
$message .= "\nTelephone: " . $contacttelInput;
$message .= "\nLocation: " . $countyCOMBO;
$headers = "From: $emailInput";
$headers .= "\nReply-To: $emailInput";
$sentOk = mail($to,$cc,$subject,$message,$headers);
echo "sentOk=" . $sentOk;
?>

adamcasey
02-07-2008, 11:43 AM
Can the moderators help on this one at all?:)

CyanBlue
02-07-2008, 12:44 PM
Howdy and Welcome... :)

I don't know where you've got an idea on adding the CC as a secondn parameter of the mail() function, but that's not correct...

Take a look at this page...
http://us3.php.net/function.mail
It says...
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
The last parameter, additional_headers, is the one you need to use to add the CC field...

If you scroll down that page, there is a sample code you can use...
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
FYI, a moderator is here to moderate the forum... Don't get confused... and we have a rule that says we don't allow anybody bumping up the post, so please don't... :(

adamcasey
02-07-2008, 01:33 PM
:o

Sorry if I broke any rules just I'm up against a tight schedule and nobody was answering me.

Thank you very much for your help I will give it a whirl.

Cheers

Adam

adamcasey
02-07-2008, 02:20 PM
OK I've amended my script (see below) and it sends me an email to the To: address but does not send a duplicate mail to the Cc: address.
What is it that I'm doing wrong?
Please help me.

<?PHP
$to = "[email protected]";
$subject = "Online Flip Book Demo Request";
$message = "Name: " . $nameInput;
$message .= "\nEmail: " . $emailInput;
$message .= "\nCompany: " . $companyInput;
$message .= "\nTelephone: " . $contacttelInput;
$message .= "\nLocation: " . $countyCOMBO;
$headers .= 'Cc: [email protected]' . "\r\n";
$headers = "From: $emailInput";
$headers .= "\nReply-To: $emailInput";
$sentOk = mail($to,$subject,$message,$headers);
echo "sentOk=" . $sentOk;
?>

CyanBlue
02-07-2008, 02:40 PM
Change these...
$headers .= 'Cc: [email protected]' . "\r\n";
$headers = "From: $emailInput";
$headers .= "\nReply-To: $emailInput";
to these and see if it works...
$headers = "From: $emailInput" . "\r\n";
$headers .= "Reply-To: $emailInput" . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
Sorry if I broke any rules just I'm up against a tight schedule and nobody was answering me.
That does not justify what's happened... Let's just make sure that does not happen again...

adamcasey
02-07-2008, 03:01 PM
How come the Cc line only has the single quote?

CyanBlue
02-07-2008, 03:21 PM
'' and "" means exactly the same in that code block... There is no difference there...

Did that or did that not work???

adamcasey
02-07-2008, 03:22 PM
Cheers Cyan you are indeed a Super Moderator.

This works fine now.

CyanBlue
02-07-2008, 03:24 PM
Here is a quick explanation on your code...

You had these...
$headers .= 'Cc: [email protected]' . "\r\n";
$headers = "From: $emailInput";
$headers .= "\nReply-To: $emailInput";
And the second line has '=' sign which reinitializes the previous value, hence the CC data is totally gone... That's why I basically needed re-order the codes...

Glad to help... :)

adamcasey
04-04-2008, 04:06 PM
I've just updated the form on my site and now the .php won't submit the data? I've not touched the .php file????
the form is after page 28 of my flash book here:http://www.tees.me.uk/booknew


All I've done is change the form by adding a 'retry' button if the users are faced with the failed to send screen.
I've added the following actionscript:

//sends the user back to the front screen of the form
//if they have recieved the failed error message.

this.retryBU.onRelease = function(){
gotoAndStop("start");
}


What is the best way to trap this error?
I thought Firebug might have pointed something out to me but it hasn't.


Original php:
<?PHP
$to = "[email protected]";
$subject = "Online Flip Book Demo Request";
$message = "Name: " . $nameInput;
$message .= "\nEmail: " . $emailInput;
$message .= "\nCompany: " . $companyInput;
$message .= "\nTelephone: " . $contacttelInput;
$message .= "\nLocation: " . $countyCOMBO;
$headers = "From: $emailInput" . "\r\n";
$headers .= "Reply-To: $emailInput" . "\r\n";
$headers .= 'Bcc:[email protected]' . "\r\n";
$sentOk = mail($to,$subject,$message,$headers);
echo "sentOk=" . $sentOk;
?>


Original Actionscript
stop();

var senderLoad:LoadVars = new LoadVars();
var receiveLoad:LoadVars = new LoadVars();


sendBU.onRelease = function() {
senderLoad.nameInput = nameInput.text;
senderLoad.emailInput = emailInput.text;
senderLoad.companyInput = companyInput.text;
senderLoad.contacttelInput = contacttelInput.text;
senderLoad.countyCOMBO = countyCOMBO.value;
senderLoad.sendAndLoad("http://www.tees.me.uk/Booknew/send.php",receiveLoad);
}

receiveLoad.onLoad = function() {
if(this.sentOk) {
_root.demoForm.gotoAndStop("success");
}
else {
_root.demoForm.gotoAndStop("failed");
}
}
// Adds conditional logic for the Submit button that
// validates user input.
this.send_BU.onRelease = function(){
if (emailInput.text == null || emailInput.text ==""){
gotoAndStop("failed");
} else {
gotoAndStop("success");
}
}

adamcasey
04-04-2008, 04:21 PM
Ignore me this was a spelling error in the path to the .php file.

jsebrech
04-07-2008, 11:32 AM
Be mindful of email injection. Sadly PHP's mail function remains a spammer favorite because if you don't take the right precautions it is trivially easy for them to abuse mail scripts to send spam (even if the to: and cc: is hardcoded in the script).

http://www.securephpwiki.com/index.php/Email_Injection

adamcasey
04-08-2008, 01:11 PM
Thanks I will check that out