大家好我在使用Gmail发送邮件时遇到问题,当我在本地主机中打开sendmail.php时说“发送失败”
继承我sendmail.ini中的代码:
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=*******@gmail.com
auth_password=******
force_sender=*******@gmail.com
的php.ini:
[mail function]
SMTP = smtp.gmail.com
smtp_port = 465
sendmail_from =*****@gmail.com
sendmail_path ="\"C:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header =关
CODE:
<?php
$to = '******@yahoo.com';
$subject = 'Test email';
$message = "Hello World!\n\nThis is my first mail.";
$headers = "From: *****@gmail.com\r\nReply-To: *****@gmail.com";
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>