我正在尝试使用php(xampp)从我的Gmail帐户发送电子邮件。 我在stackoverflow上搜索,当我得到的东西我改变了我的xampp的文件sendmail.ini和php.ini as,
在C:\ xampp \ php \ php.ini中,我从行extension=php_openssl.dll
的开头删除了分号,以使SSL为本地主机的gmail工作。
在[mail function]下的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.
答案 0 :(得分:0)
使用您的真实电子邮件地址来收发电子邮件。
$ to =&#39; myeamilid@gmail.com' ;;将其替换为您的真实电子邮件地址