【问题标题】:send email to specific email id from localhost using xampp [duplicate]使用xampp从本地主机向特定的电子邮件ID发送电子邮件[重复]
【发布时间】:2019-08-05 14:48:05
【问题描述】:

我正在尝试从 localhost 向特定的电子邮件 ID 发送邮件。

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

现在我有以下配置:

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"

SENDMAIL.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 放在哪里,邮件将从哪里发送给其他人。

请帮忙! 谢谢

【问题讨论】:

  • 有一些像我提到的东西,用什么来代替这些或保留它们,例如 force_sender=@gmail.com 像尖括号等,我应该使用我自己的gmail id? @戴夫
  • 或者请告诉我如何查看我的错误(如果有),因为我不知道问题出在哪里,你提到的链接,我已经访问过很多次了前。 @RiggsFolly
  • 好的,好的!将error reporting 添加到您的文件顶部测试时 在您打开PHP 标记之后,例如&lt;?php error_reporting(E_ALL); ini_set('display_errors', 1); 以查看它是否产生任何结果。
  • 好的,我会的。你能看看上面的代码,它应该工作得很好还是缺少什​​么? @RiggsFolly 你怎么看?
  • sendmail.ini 添加error_logfile=sendmail_error.logdebug_logfile=sendmail_debug.log 或快速阅读The manual

标签: php email xampp localhost


【解决方案1】:

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

【讨论】:

  • 我已经这样做了,问题的最后部分也提到了
猜你喜欢
  • 1970-01-01
  • 2016-07-22
  • 2015-08-07
  • 2013-10-01
  • 2010-12-19
  • 2013-12-18
相关资源
最近更新 更多