【问题标题】:Website Email Form (PHP) Issues网站电子邮件表单 (PHP) 问题
【发布时间】:2016-02-23 21:42:33
【问题描述】:

我知道这是经常被问到的问题之一,但在涉及更多技术问题时,我并不是最精明的网页设计师。问题是这样的:在我的网站 www.imago-graphics.com 上,来自联系人部分的电子邮件没有发送到任何地方:既不是我的 iPage 收件箱,也不是我的 Google Apps 电子邮件。我知道这可能是 mail.php 的问题,但我不确定它是什么。这是 php(我在脚本中留下了我希望它转到的实际电子邮件地址 (mariano@imago-graphics.com),但取出了密码;此外,该地址是 Google Apps 电子邮件地址,我认为可能是问题的一部分:

<?
require("class.phpmailer.php");


    //form validation vars
    $formok = true;
    $errors = array();

    //sumbission data
    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $date = date('d/m/Y');
    $time = date('H:i:s');

    //form data
    $name = $_POST['name']; 
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];


$mail = new PHPMailer();

$mail->IsSMTP();                                         // send via SMTP
$mail->Host     = "smtp.gmail.com";                  // SMTP server
$mail->SMTPAuth = true;                      // turn on SMTP authentication
$mail->Username = "mariano@imago-graphics.com";          // SMTP username
$mail->Password = "xxxxx";               // Password

$mail->From     = "mariano@imago-graphics.com";          // SMTP username again
$mail->AddAddress("mariano@imago-graphics.com");         // Your Adress
$mail->Subject  =  "New mail from IMAGO Graphics";
$mail->IsHTML(true);  
$mail->CharSet = 'UTF-8';
$mail->Body     =  "<p>You have recieved a new message from the enquiries form on your website.</p>
                      <p><strong>Name: </strong> {$name} </p>
                      <p><strong>Email Address: </strong> {$email} </p>
                      <p><strong>Subject: </strong> {$subject} </p>
                      <p><strong>Message: </strong> {$message} </p>
                      <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";

if(!$mail->Send())
{
   echo "Mail Not Sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Mail Sent";


?>

【问题讨论】:

  • 您确定 google 是您的 smtp 主机吗?你在使用谷歌应用吗?
  • 设置 $mail-&gt;SMTPDebug 将帮助您从 SMTP 跟踪错误,非常有助于收集您需要的所有线索。
  • Matt:是的,我使用的是 Google Apps,上面的电子邮件是 Google Apps 地址。我知道这可能是问题的根源,但就像我说的,我更像是一名平面设计师而不是编码员。感谢您的回复!
  • MackieeE:谢谢,我会调查的。
  • 您确定您的服务器可以为imago-graphics.com 发送(中继)电子邮件吗?

标签: php email webmail


【解决方案1】:

您还需要设置一些参数才能从 Gmail 帐户发送。请查看他们的文档,了解您需要使用的最新 SMTP 设置。

这些是你必须拥有的几样东西:

$mail->Username   = "mariano@imago-graphics.com";
$mail->Password   = "xxxxx"; 
$mail->SMTPSecure = "tls";
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 587;    

在测试期间启用调试模式,以便您可以查看是否有错误:

$mail->SMTPDebug  = 2;  

【讨论】:

    猜你喜欢
    • 2012-10-17
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 2011-08-28
    • 1970-01-01
    • 2021-04-03
    相关资源
    最近更新 更多