Jump to content

Send Mail - Mail function.


ROCKSTAR

Recommended Posts

Hey guys,

 

I'm trying to send mail through a form, I've followed a number of tutorials and it seems as if the code is correct, it doesnt error but I don't get any mail through.. the code for my sendmail.php is below - any pointers would be great.

 

<?

 

$name=$_POST['name'];

 

$email=$_POST['email'];

 

$comment=$_POST['comments'];

 

$to="[email protected]";

 

mail($to, "Message from my PHP page", $comment, $email);

 

?>

Link to comment
https://forums.phpfreaks.com/topic/93357-send-mail-mail-function/
Share on other sites

The 4th argument needs to be a header. Something like this should work:

 

 

<?php
$name=$_POST['name'];
$email=$_POST['email'];
$comment=$_POST['comments'];

$to="[email protected]";
$subject = "Message from my PHP page";
$headers  = "From: $email\r\n";

mail($to, $subject, $comment, $headers)
  or die("Couldn't send mail");
?>

Another problem that is becoming more common is a hosting service blocking mail with a FROM header that is outside the domain. Trying using a FROM header with an email address from your domain.

 

So, let's forget out the POST for now, and just get email working. Assuming your domain is 'mydomain.co.uk', try this:

 

<?php
$to="[email protected]";
$from="[email protected]";
$subject = "Message from my PHP page";
$comment = "My message goes here";

mail($to, $subject, $comment, "From: $email")
  or die("Couldn't send mail");
print "Email Sent";
?>

 

Also, if you have a spam filter make sure you check that.

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.