This question already has an answer here:
这个问题在这里已有答案:
- PHP mail function doesn't complete sending of e-mail 24 answers
PHP邮件功能没有完成发送电子邮件24个答案
I am using the php mail() function to send mails from my server. It was working fine before but now I am not getting the simple mail. Mail status is TRUE but emails are not being received. I tested it on the other server its working fine there.
我正在使用php mail()函数从我的服务器发送邮件。它之前工作正常,但现在我没有得到简单的邮件。邮件状态为TRUE,但未收到电子邮件。我在其他服务器上测试了它在那里的工作正常。
Here is my code:
这是我的代码:
$to = 'myemail@gmail.com';
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone_number = trim($_POST['phone']);
$message = trim($_POST['message']);
$subject = 'Contact Message from - ' . strip_tags($name);
$headers = "From: " . $name . " <" . $email . "> \r\n";
$headers .= "Reply-To: " . strip_tags($email) . "\r\n";
$headers .= "Content-type: text/html \r\n";
$message = '<html><body>';
$message .= '<h1>Hello, </h1>';
$message .= '</body></html>';
$message .= '<html><body>';
$message .= '<table rules="all" style="border-color: #666; border:1px solid;" cellpadding="10">';
$message .= "<tr><td><strong>Name:</strong> </td><td>" . $name . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . $email . "</td></tr>";
$message .= "<tr><td><strong>Phone Number:</strong> </td><td>" . $phone_number . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . $message . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
$confirmation = mail($to, $subject, $message, $headers);
if ($confirmation) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.php\">";
} else {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
}
2 个解决方案
#1
0
At first check a simple mail.
首先检查一个简单的邮件。
<?php
ini_set('display_errors',1);
$email = '';//<--your mail
if (mail($email, 'test', 'test') {
echo 'send';
} else {
echo 'problems';
}
Run it. Check your email, if do not send - see errors on display.
运行。检查您的电子邮件,如果不发送 - 请参阅显示的错误。
#2
0
Check server's SMTP setting may be its incorrect, alternative you can use this simple SMPT send mail script.
检查服务器的SMTP设置可能是不正确的,您可以使用此简单的SMPT发送邮件脚本。
#1
0
At first check a simple mail.
首先检查一个简单的邮件。
<?php
ini_set('display_errors',1);
$email = '';//<--your mail
if (mail($email, 'test', 'test') {
echo 'send';
} else {
echo 'problems';
}
Run it. Check your email, if do not send - see errors on display.
运行。检查您的电子邮件,如果不发送 - 请参阅显示的错误。
#2
0
Check server's SMTP setting may be its incorrect, alternative you can use this simple SMPT send mail script.
检查服务器的SMTP设置可能是不正确的,您可以使用此简单的SMPT发送邮件脚本。