0

I am working on a simple contact form and the php script is not sending an email to my email... The script is running succesfully and it produces the HTML output seen in the code below. I am trying to figure it out, yet I just cannot get it to send the email. I have looked at tutorials and appear to have the same exact code as a lot of the tutorials out there. I am using a form to get user's input seen here,

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dummy Code - Contact</title>
</head>

<body>

<form action="send_simpleform.php" method="post">
<p>Your name<br />
<input name="sender_name" type="text" size="30" /></p>
<p>Email<br  />
<input name="sender_email" type="text" size="30" /></p>
<p>Message<br />
<textarea name="message" cols="30" rows="5"></textarea></p>
<input name="submit" type="submit" value="Submit" />
</form>

</body>
    </html>

My PHP script can be seen here as well,

<?php
$msg = "Email sent from www.dummycode.com\n";
$msg .= "Sender's Name:\t $_POST[sender_name]\n";
$msg .= "Sender's E-mail:\t $_POST[sender_email]\n";
$msg .= "Sender's Message:\t $_POST[message]\n";
$to = "henry.harris@xxxxxxxxxxx.com";
$subject = "DummyCode.com";
$headers = "From: My web site <www.dummycode.com>\n";
$headers .= "Reply to: $_POST[sender_email]\n";
mail($to, $subject, $msg, $headers);
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dummy Code Contact Sent</title>
</head>

<body>

<h1>The following email has been sent</h1>

<p>Your Name:<br />
<? echo "$_POST[sender_name]"; ?>
<p>Your Email Adress:<br />
<? echo "$_POST[sender_email]"; ?>
<p>Message:<br />
<? echo "$_POST[message]"; ?>
</p>
</body>
</html>

I know I am pretty knew at this and if this is a stupid error on my part, then I'm sorry. I am pretty dumb. Thanks in advance. Please don't hate.

-Henry

4

3 に答える 3

1

The only thing you can do in your script, is check the return value of the mail() function.

If true, the message was successfully accepted for delivery. However, that does not mean that the message was actually sent.

Simple example:

if (mail(...))
{
  // mail was accepted for delivery
}
else
{
  // not accepted
}
于 2013-03-08T21:45:24.440 に答える
0

You should take a look at swiftmailer. Setup is fast an simple and it's VERY well documented. Error handling is top notch!

于 2013-03-08T23:25:41.537 に答える
0

Well, I have had situations where mails seemed sent but I can't see it in the inbox I'm sending it to. So here are a few things I do:

  1. Don't send from localhost except you have a mail server that can send outbound messages
  2. Preferably, send or test your mail script on your remote server
  3. Ensure the senders email address is same as the originating domain
  4. Don't use reply emails that are different from sender's email - it could be eaten up as a spam or junked by most email clients
  5. Verify the allowed smtp port of your server and set that
  6. Verify the smtp server and set that
  7. Provide actual credentials for the sending email
  8. Place the user's email somewhere in the body of the message with a mailto: link so you could quickly reply them. (If they are sending to you using the script). If you are sending to them, no need specifying a different reply-to
  9. Ensure to specify the encoding charset, newline character and possibly word-wrap features that should word
  10. Try using a tested PHP Class from phpclasses.org

I take them one at a time and usually get my mails sent doing what's right. In your code, try adjusting these lines and testing too:

$headers = "From: My web site <www.dummycode.com>\n"; //Same as originating domain or email (just for tweaks)
$headers .= "Reply to: $_POST[sender_email]\n"; //Should be same as sender's email for a try
于 2013-03-10T05:13:31.847 に答える