0

我有一个设置为使用 PHPmailer 将网站发送到同一域的电子邮件地址的网站,但我无法让它连接到 SMTP 服务器。

这是我的电子邮件配置文件中的一部分:

$config = (object) array();

$config->email_from_addr      = "noreply@mywebsite.com";
$config->email_host           = "mail.mywebsite.com";
$config->email_from_password  = '********';
$config->email_from_name      = "Title";

$config->email_to             = 'info@mywebsite.com';
$config->email_subject        = "Contact email from mywebsite";

用于发送电子邮件的 PHP 在这里:

$phpmailer = new PHPMailer();
$phpmailer->IsSMTP();                                             // set mailer to use SMTP
if($config->use_gmail == true)
{
    $phpmailer->Port = 465;
    $phpmailer->Host = "smtp.gmail.com";
}
else
{
    $phpmailer->Host = $config->email_host;                 // specify main and backup server
}
$phpmailer->SMTPAuth = true;                                // turn on SMTP authentication
$phpmailer->Username = $config->email_from_addr;            // SMTP username
$phpmailer->Password = $config->email_from_password;        // SMTP password

$phpmailer->From = $config->email_from_addr;
$phpmailer->FromName = $config->email_from_name;
$phpmailer->AddAddress($config->email_to);

$phpmailer->WordWrap = 80;                                   // set word wrap to 80 characters
$phpmailer->IsHTML(true);                                    // set email format to HTML

$phpmailer->Subject = $config->email_subject;
$phpmailer->Body    = $message;
$phpmailer->AltBody = $message;

?>
<div style="float:left; display:block; background:#F1F1F1; margin:26px 0 60px 10px; height:200px; padding-top:140px; width:330px; text-align:center; font-size:16px; font-weight:bold" class="red"> 
<?php
if(@!$phpmailer->Send())
{
?>
<br />
<br />
Your email could not be sent.
<?php   
}
else
{
?>
Your email has been sent. Someone will reply to it shortly.
<?php

我只是不知道为什么它没有连接到我的邮件服务器。或者,也许我做错了什么。

4

1 回答 1

0

尝试if(!(@$phpmailer->Send()))代替if(@!$phpmailer->Send())

于 2012-08-03T15:21:04.797 回答