我的邮件不是通过 PHP 功能邮件()发送的


my mails are not getting sent by php funtion mail()

我正在尝试使用php(xampp)从我的gmail帐户发送电子邮件。我搜索堆栈溢出,当我得到的东西时,我更改了 xampp 的文件 sendmail.ini 和 php.ini 作为,

在 C:''xampp''php''php 中.ini我删除了行首的分号extension=php_openssl.dll以使 SSL 适用于本地主机的 gmail。

在 php.ini [邮件功能] 下的文件我更改了

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = mukul.agrawal19@gmail.com
sendmail_path = "'"C:'xampp'sendmail'sendmail.exe'" -t"

然后在 C:''xampp''sendmail''sendmail.ini 中。我用以下代码替换了 sendmail 中的所有现有代码.ini

[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=mukul.agrawal19@gmail.com
auth_password=my-gmail-password
force_sender=mukul.agrawal19@gmail.com

然后我写了一个简单的邮件函数

<?php
$to = 'mukulagrawal13@live.com';
$subject = 'Test email'; 
$message = "Hello World!'n'nThis is my first mail."; 
$headers = "From: webmaster@example.com'r'nReply-To: webmaster@example.com";
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>

然后通过我的浏览器进入此页面,收到回声,因为邮件失败。

看到了我的调试文件,我得到了

14/12/03 18:24:00 ** --- MESSAGE BEGIN ---
14/12/03 18:24:00 ** To: mukulagrawal13@live.com
14/12/03 18:24:00 ** Subject: Test email
14/12/03 18:24:00 ** From:mukul.agrawal19@gmail.com
14/12/03 18:24:00 ** Reply-To:mukul.agrawal19@gmail.com
14/12/03 18:24:00 ** 
14/12/03 18:24:00 ** Hello World!
14/12/03 18:24:00 ** 
14/12/03 18:24:00 ** This is my first mail.
14/12/03 18:24:00 ** --- MESSAGE END ---
14/12/03 18:24:01 ** Connecting to smtp.gmail.com:25
14/12/03 18:24:08 ** Connected.
14/12/03 18:24:08 << 220 mx.google.com ESMTP o17sm23150442pdn.33 - gsmtp<EOL>
14/12/03 18:24:08 >> EHLO Mukul-PC<EOL>
14/12/03 18:24:10 << 250-mx.google.com at your service, [223.186.182.29]<EOL>250-SIZE 35882577<EOL>250-8BITMIME<EOL>250-STARTTLS<EOL>250-ENHANCEDSTATUSCODES<EOL>250-PIPELINING<EOL>250-CHUNKING<EOL>250 SMTPUTF8<EOL>
14/12/03 18:24:10 ** Authenticating as mukul.agrawal19@gmail.com
14/12/03 18:24:10 >> STARTTLS<EOL>
14/12/03 18:24:12 << 220 2.0.0 Ready to start TLS<EOL>
14/12/03 18:24:14 >> QUIT<EOL>
lots of codes in unknown language.
14/12/03 18:21:47 ** Disconnected.
14/12/03 18:21:47 ** Disconnecting from smtp.gmail.com:25
14/12/03 18:21:47 ** Disconnected.
14/12/03 18:21:47 ** Disconnected.
14/12/03 18:21:47 ** Connection Closed Gracefully.

使用您的真实电子邮件地址来获取电子邮件。

$to = 'myeamilid@gmail.com';将其替换为您的真实电子邮件地址