php - 使用 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 放在哪里,邮件将从哪里发送给其他人。
请帮忙 !谢谢
解决方案
默认情况下,Gmail 不允许这样做。检查您的 google 帐户设置并允许访问不太安全的应用程序。或生成应用专用密码并在此处使用。
推荐阅读
- rust - 有没有办法获得对 std::i32::MIN 执行正确操作的 i32 的 u32 绝对值?
- android - ActivityResult 后恢复片段状态
- python-3.x - 你如何以字节的形式下载图像?
- php - WordPress 管理员用户不应登录到 WooCommerce 帐户页面
- vb.net - 将变量传递给新表单与打开表单
- android - 限制移动设备的悬停功能
- angular - angular.json 资产属性更改不起作用
- php - Laravel 雄辩的多属于播种
- arcgis - 附加到重叠图形的 PopupTemplate 的功能导航
- java - 在 indexOf 和 lastIndexOf 中使用正则表达式