php邮件程序无法发送电子邮件 [英] php mailer could not send email

查看:136
本文介绍了php邮件程序无法发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP从localhost发送电子邮件。这是我的代码:

I am trying to send an email from localhost with PHP. Here is my code:

<?php

// $email and $message are the data that is being
// posted to this page from our html contact form
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

require_once('class.phpmailer.php');
require 'PHPMailerAutoload.php';
require 'class.smtp.php';

$mail = new PHPMailer();

$mail->IsSMTP();

$mail->Host = "localhost";  // specify main and backup server

$mail->SMTPAuth = false;     // turn on SMTP authentication

$mail->Username = "TTTTTT@gmail.com";  // SMTP username
$mail->Password = ""; // SMTP password
$mail->Port = 25;   
$mail->SMTPSecure = '';  

$mail->From = $email;

$mail->AddAddress("bradm@inmotiontesting.com", "Brad Markle");

$mail->WordWrap = 50;

$mail->IsHTML(true);

$mail->Subject = "You have received feedback from your website!";

$mail->Body    = $message;
$mail->AltBody = $message;

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?>

当我运行此代码时,会显示消息已发送,但实际上并不发送消息。我的问题是什么?

When I run this code, it shows, "message has been sent" but it does not actually send the message. What is my problem?

推荐答案

除了Lelio Faieta发布的内容外,启用Gmail中较不安全的应用

In addition to what Lelio Faieta posted, enable less secure apps in gmail

并阻止您的邮件进行对您的垃圾邮件
更改

and to prevent your mail going to your spam change

$mail->From = $email;

给您的电子邮件,您可以将$ email放在您的邮件正文中

to your email and you can put $email in body of your message

这篇关于php邮件程序无法发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆