我在php中编写了以下代码并保存为电子邮件.php
<?php
$to = "gomathi@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "gomathi@gmail.com";
$headers = "From:" . $from;
if( mail($to,$subject,$message,$from) )
echo "Mail Sent to ur id check it .";
else
echo "Mail not Sent";
?>
我更改了要发送的电子邮件的配置文件。 1)更改了发送邮件.ini如下所示:
smtp_server=smtp.gmail.com
smtp_port=587
default_domain= gmail.com
auth_username=gomathii@gmail.com
auth_password=XXXXX
force_sender= gomathi@gmail.com
2)更改了PHP.ini邮件功能,如下所示:
SMTP =smtp.gmail.com
smtp_port = 587
sendmail_from = gomathi@gmail.com
sendmail_path = "'"C:'xampp'sendmail'sendmail.exe'" -t"
现在我在浏览器中运行电子邮件.php它返回"邮件已发送到您的身份证检查它"。 但是没有收到来自 gomathi@gmail.com 的邮件。 为什么没有收到请帮助我解决这个问题。
您似乎向邮件传递了不正确的参数,并且您的$headers从未被使用过。
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
考虑在标头中传入 To & Subject。
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
并在电子邮件地址中添加尖括号。
完整的工作示例应该是:
<?php
$to = "<gomathi@gmail.com>";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "<gomathi@gmail.com>";
$headers = "From:" . $from;
if( mail($to,$subject,$message,$headers) )
echo "Mail Sent to ur id check it .";
else
echo "Mail not Sent";
?>
此外,请考虑使用 SSL 端口 465。