我正在尝试通过localhost(XAMPP)在php中使用电子邮件功能发送电子邮件,但是电子邮件未发送。我该如何实现?

时间:2020-04-07 05:08:36

标签: php html email

我如何使用localhost(xampp)在php上使用mail函数发送电子邮件? 我的php.ini文件是:

SMTP = smtp.gmail.com  
smtp_port = 465 
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
sendmail_from = senders email

我的sendmail.ini文件是:

smtp_server=smtp.gmail.com
smtp_port=465 
error_logfile=error.log
debug_logfile=debug.log
auth_username=email address
auth_password=password
force_sender=sender's email

我的代码是:

$to_email = "email address";
$subject = "Subject";
$body = "msg";
$headers = "From: email address";

if (mail($to_email, $subject, $body, $headers)) {
    echo "Email successfully sent to $to_email...";
} else {
    echo "Email sending failed...";
}

0 个答案:

没有答案