使用PHP向gmail帐户发送电子邮件
我正在尝试从我的网站向gmail帐户发送邮件。似乎在代码级别上一切都很好。你们能研究一下这个问题吗:即使我运行这个脚本,邮件也不会被发送到gmail帐户使用PHP向gmail帐户发送电子邮件,php,Php,我正在尝试从我的网站向gmail帐户发送邮件。似乎在代码级别上一切都很好。你们能研究一下这个问题吗:即使我运行这个脚本,邮件也不会被发送到gmail帐户 <?php if(isset($_POST['submit'])){ ini_set('SMTP','localhost'); $msg='Name : '.$_POST['name']."\n" .'Email : '.$_POST['email']."
<?php
if(isset($_POST['submit'])){
ini_set('SMTP','localhost');
$msg='Name : '.$_POST['name']."\n"
.'Email : '.$_POST['email']."\n"
.'Message : '.$_POST['message'];
mail("aa@gmail.com","Message from Contact Us",$msg);
}
else{
echo 'cannot send email';
}
?>
我认为您将安装phpmailer(),然后通过smtp发送。下面是示例代码:
require_once "Mail.php";
$from = '<from@gmail.com>';
$to = '<to@yahoo.com>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'your gmail ',
'password' => 'your password'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
require_once“Mail.php”;
$from='';
$to='';
$subject='Hi!';
$body=“您好,\n\n您是什么人?”;
$headers=数组(
'From'=>$From,
'至'=>$至,
“主题”=>$Subject
);
$smtp=Mail::工厂('smtp',数组(
'主机'=>'ssl://smtp.gmail.com',
“端口”=>“465”,
“auth”=>正确,
“用户名”=>“你的gmail”,
'密码'=>'您的密码'
));
$mail=$smtp->send($to、$headers、$body);
if(PEAR::isError($mail)){
echo(“”.$mail->getMessage()。”);
}否则{
回显(“消息已成功发送!”);
您是否在本地安装了SMTP?可能与的重复