<?php
$sendto = "account@gmail.com";
$subject = "email confirmation"; // Subject
$message = "the body of the email - this email is to confirm etc...";
# send the email
mail($sendto, $subject, $message);
?>
这是我编写的用于测试localhost上的邮件功能的代码。 我已经在浏览器中运行了几次脚本,但仍然在我的邮箱中收到任何电子邮件。
我是否需要任何其他配置?
提前thx!答案 0 :(得分:0)
您需要确保已将PHP安装设置为使用有效的SMTP服务器。您可以在answers to this question找到您要找的内容。如果不这样做,您可能需要在实时Web服务器上测试脚本。
答案 1 :(得分:0)
基本上很难从localhost向任何邮件提供商发送邮件。 他们对传入的邮件有很大的限制,而简单的mail()将无法正常工作。
您需要使用SMTP服务器。 并在php配置中定义该服务器
smtp = localhost #(here should be your smtp server)
smtp_port = 25
如果您没有SMTP服务器,请尝试传递所有标头,例如PHP示例:
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
答案 2 :(得分:0)
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<?php
$email_from = 'yourname@yourwebsite.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message"
?>
<?php
$to = "inspiretechpark@gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
<?php
$to = "name1@website-name.com, name2@website-name.com,name3@website-
name.com";
mail($to,$email_subject,$email_body,$headers);
?>
<?php
$to = "name1@website-name.com, name2@website-name.com,name3@website-
name.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
$headers .= "Cc: someone@domain.com \r\n";
$headers .= "Bcc: someoneelse@domain.com \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
试试这个家伙......这是发送邮件
答案 3 :(得分:0)
尝试一下:
<?php
$sender = 'email@example.com';
$recipient = 'email@example.com';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
?>
答案 4 :(得分:-1)
如果你正在使用localhost,我希望它永远不会工作。它仅适用于邮件配置的服务器。请尝试一下。