使用gmail xampp发送php电子邮件不起作用
但每当我提交并执行文件时,电子邮件都不会发送到我的gmail 我已经在xampp中更改了php.ini,其中sendmail_路径不以“;”开头 在sendmail.ini中,我还将smtpp_服务器更改为smtp.gmail.com。以及smtp端口到587(也尝试了465)。最后,我将auth_用户名和auth_密码更改为我的电子邮件和密码。但代码仍然不起作用 我正在使用Windows8使用gmail xampp发送php电子邮件不起作用,php,gmail,Php,Gmail,但每当我提交并执行文件时,电子邮件都不会发送到我的gmail 我已经在xampp中更改了php.ini,其中sendmail_路径不以“;”开头 在sendmail.ini中,我还将smtpp_服务器更改为smtp.gmail.com。以及smtp端口到587(也尝试了465)。最后,我将auth_用户名和auth_密码更改为我的电子邮件和密码。但代码仍然不起作用 我正在使用Windows8 <?php mail('hello.3i@gmail.com', 'sample mail', '
<?php
mail('hello.3i@gmail.com', 'sample mail', 'sample content', 'From: freak@freakzoid.com');
?>
如果要从本地主机发送邮件,应通过以下方式配置sendmail.ini 您可以使用sendmail包sendmail从localhost发送邮件 包在XAMPP中内置。因此,如果您使用的是XAMPP,那么您可以 轻松地从本地主机发送邮件 例如,您可以配置
C:\xampp\php\php.ini
和
c:\xampp\sendmail\sendmail.ini
供gmail发送邮件。在里面
C:\xampp\php\php.ini
查找extension=php\u openssl.dll
并删除
该行开头的分号,用于使SSL工作
本地主机的gmail
在php.ini文件中找到[mail function]
并进行更改
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@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=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com
现在你做到了!!使用邮件功能创建php文件并发送邮件
从本地主机
注:别忘了更换我的gmail id和我的gmail密码
在上面的代码中。此外,如果需要,请不要忘记删除重复的密钥
从上面复制了设置。例如,注释在下面一行,如果
还有另一个发送邮件路径:
php.ini中的sendmail\u path=“C:\xampp\mailtodisk\mailtodisk.exe”
文件
还记得使用XAMMP控制面板重新启动服务器,以便
这些变化将生效
应该配置SMTP。
C:\xampp\sendmail\sendmail.ini
和C:\xampp\php\php.ini
此外,您还可以轻松使用:
hi,在我用mail函数执行php文件之后。邮件最终位于xampp中的my mailoutput文件夹中。你知道怎么修吗?
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}