我正在尝试使用localhost
(XAMPP v3.2.1)发送电子邮件。为此,我需要重新配置php.ini
和sendmail.ini
文件。到目前为止,我所做的是,我在相应的文件中更改了以下内容。
在php.ini
我已更改为:
extension=php_openssl.dll (I Remove the semicolon from beginning)
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
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=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com
出于测试目的,我编写了一个index.php
文件,如下所示:
<!DOCTYPE html>
<html>
<head>
<title>Sending HTML email using PHP</title>
</head>
<body>
<?php
$to = "testMailId@gmail.com";
$subject = "This is subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:senderMailId @gmail.com \r\n";
$header .= "senderMailId @gmail.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to, $subject, $message, $header);
if($retval == true ) {
echo "Message sent successfully...";
} else {
echo "Message could not be sent...";
}
?>
</body>
</html>
但结果显示无法发送消息。我不知道配置或代码是否有任何问题?请帮忙。