首页 > 解决方案 > 使用 xampp 从本地主机向特定的电子邮件 ID 发送电子邮件

问题描述

我正在尝试从本地主机向特定的电子邮件 ID 发送邮件。

我已经阅读 了这个这个以及其他一些帖子,但这并没有解决我的问题。

现在我有以下配置:

PHP.ini

[mail function]
; *For Win32 only*.
; http://php.net/smtp
SMTP=smtp.gmail.com
; http://php.net/smtp-port
smtp_port=587
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = mypersonal@gmail.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

发送邮件.ini

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=mypersonal@gmail.com
auth_password=my above email password
force_sender=mypersonal@gmail.com

**PHP代码是**

$to = "someFriend@gmail.com";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <mypersonal@gmail.com>' . "\r\n";


$check = mail($to,$subject,$message,$headers);
if($check == true){
    echo "successfully mail Sent";
}
else{
    echo "Email sending Failed";
}

我明白Email sending failed了,这个配置或代码有什么问题吗?我还允许我的 Gmail 使用不太安全的应用程序

我也很困惑将我自己的 gmail id 放在哪里,邮件将从哪里发送给其他人。

请帮忙 !谢谢

标签: phpemailxampplocalhost

解决方案


默认情况下,Gmail 不允许这样做。检查您的 google 帐户设置并允许访问不太安全的应用程序。或生成应用专用密码并在此处使用。


推荐阅读