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="me@mydomain.co.uk";

 

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

 

?>

Link to comment
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="me@mydomain.co.uk";
$subject = "Message from my PHP page";
$headers  = "From: $email\r\n";

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

Link to comment
Share on other sites

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="me@mydomain.co.uk";
$from="info@mydomain.co.uk";
$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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.