Jump to content

php email script


tom_b

Recommended Posts

Hi,

 

Well, I got my mail server working, I can now send e-mails from my computer, however, the message doesn't show up when i get the e-mail, here's the script:

 

<?php

$sendTo = "[email protected]";

$subject = "php e-mail test";

$headers = "From: Tom ";

$message = "this is the message";

//$headers = "Reply-To: " . $_POST["email"] . "\r\n";

//$headers = "Return-Path: " . $_POST["email"];

 

mail($sendTo, $subject, $headers, $message);

?>

 

What' wrong here?

 

Thanks, Tom

 

Link to comment
https://forums.phpfreaks.com/topic/37391-php-email-script/
Share on other sites

First of all you have to use the correct syntax for mail():

 

http://no.php.net/manual/en/function.mail.php

bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )

 

So your piece of code will look like:

 

mail($sendTo, $subject, $message, $headers); 

 

And when you are dealing with functions that return false for failure and true for success you should use it:

 


<?PHP
$sendmail = mail($sendto,$subject,$message,$headers);

if($sendmail){
  echo "Mail sent successfully";
}
else{
  echo "Sending failed..";
}

?>

 

If the mail is succesfully sent $sendmail will be set to true and your script will print "Mail sent successfully",  otherwise it will print "Sending failed..".

Link to comment
https://forums.phpfreaks.com/topic/37391-php-email-script/#findComment-178732
Share on other sites

I missed the // in front of both your $headers and actually misunderstood your problem You do receive the e-mail due to a little bit of luck:

 

#1: You do use the wrong syntax: mail($sendto,$subject,$headers,$message) which should have been: mail($sendto,$subject,$message,$headers)

 

#2: Therefore the script sends $headers as the message and $headers is empty because you have commented those out using // hence the "message is not showing up" :)

 

#3: And for some reason it can deal with "this is the message" as a header and does not give you an error....

 

Best regards

Wuhtzu

Link to comment
https://forums.phpfreaks.com/topic/37391-php-email-script/#findComment-178737
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.