[英]PHP email won't send to my email
I have some problems with sending and receiving emails with my code.. 我在发送和接收带有我的代码的电子邮件时遇到了一些问题。
When I try this code on my localhost(XAMPP) it says: Email send, but when i look in my mail i didn't receive the mail.. can someone help? 当我在本地主机(XAMPP)上尝试此代码时,它说:电子邮件发送,但是当我查看邮件时,我没有收到邮件..有人可以帮忙吗? My code: 我的代码:
<?php
// $EmailFrom = "ME";
$EmailTo = "My_amail_adress";
$Subject = "My_subject";
$Name = stripslashes($_POST['Name']);
$Email = stripslashes($_POST['Email']);
$Message = stripslashes($_POST['Message']);
//setup the email
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$success = mail($EmailTo, $Subject, $Body); //"From: <$EmailFrom>"
if ($success) {
echo "Email send";
}
else{
echo "Error, please try again";
}
?>
Do you have SMTP server configured in your localhost ? 您在本地主机中配置了SMTP服务器吗?
You can send mail from localhost with sendmail package , sendmail package is inbuild in XAMPP. 您可以使用sendmail软件包从本地发送邮件,sendmail软件包在XAMPP中是内置的。 So if you are using XAMPP then you can easily send mail from localhost. 因此,如果您使用的是XAMPP,则可以轻松地从本地主机发送邮件。
for example you can configure C:\\xampp\\php\\php.ini and c:\\xampp\\sendmail\\sendmail.ini for gmail to send mail. 例如,您可以将C:\\ xampp \\ php \\ php.ini和c:\\ xampp \\ sendmail \\ sendmail.ini配置为gmail以发送邮件。
in C:\\xampp\\php\\php.ini find extension=php_openssl.dll and remove the semicolon from the beginning of that line to make SSL working for gmail for localhost. 在C:\\ xampp \\ php \\ php.ini中找到extension = php_openssl.dll,并从该行的开头删除分号,以使SSL适用于localhost的gmail。
in php.ini file find [mail function] and change 在php.ini文件中找到[邮件功能]并进行更改
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Now Open C:\\xampp\\sendmail\\sendmail.ini. 现在打开C:\\ xampp \\ sendmail \\ sendmail.ini。 Replace all the existing code in sendmail.ini with following code 用以下代码替换sendmail.ini中的所有现有代码
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com
Now you have done!! 现在您已经完成了!! create php file with mail function and send mail from localhost. 使用邮件功能创建php文件,并从本地主机发送邮件。
PS: don't forgot to replace my-gmail-id and my-gmail-password in above code. PS:不要忘记在上面的代码中替换my-gmail-id和my-gmail-password。 Also, don't forget to remove duplicate keys if you copied settings from above. 另外,如果您从上方复制设置,请不要忘记删除重复的键。 For example comment following line if there is another sendmail_path : sendmail_path="C:\\xampp\\mailtodisk\\mailtodisk.exe" in the php.ini file 例如,如果在php.ini文件中还有另一个sendmail_path,则在下一行添加注释:sendmail_path =“ C:\\ xampp \\ mailtodisk \\ mailtodisk.exe”
If you are working on localhost
you can not send emails by default , you need to configure sendmail
如果您在localhost
上工作,则默认情况下无法发送电子邮件,需要配置sendmail
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.