使用PHPMailer使用GoDaddy托管发送电子邮件?

时间:2017-08-03 04:42:00

标签: php email phpmailer

我目前正致力于为我的虚拟公司建立一个网站,我一直在研究,无法在任何地方找到答案。

当用户注册时,我希望他们收到一封电子邮件,简要介绍该公司。这是我使用的代码(是的,$ _SESSION变量确实有值

<?php
session_start();

require '../../PHPMailer/PHPMailerAutoload.php';

$EmailUsername = $_SESSION['Username'];
$EmailFirstName = $_SESSION['FirstName'];
$EmailEmail = $_SESSION['Email'];

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'localhost';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'no-reply@ozzietransport.org';                 // SMTP username
$mail->Password = '#Password';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25;                                       // TCP port to connect to

$mail->setFrom('no-reply@ozzietransport.org', 'No-Reply');
$mail->addAddress($EmailEmail, $EmailFirstName);     // Add a recipient
$mail->addAddress('');               // Name is optional
$mail->addReplyTo('', '');
$mail->addCC('');
$mail->addBCC('');

$mail->addAttachment('');         // Add attachments
$mail->addAttachment('');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Ozzie Transport Signup';
$mail->Body    =    "Hello, $EmailUsername.
                    <br><br>
                    Welcome to <b>Ozzie Transport.</b> A Virtual Trucking Company Utilising Truckers MP’s Multiplayer's Servers on Both American Truck Simulator and European Truck Simulator 2.
                    <br><br>
                    <b>Ozzie Transport</b> was founded by <i>Mr. Will Lads</i> and <i>Mr. Jacob Findlater</i>. Who where major assets to Ozzie Transport's Beginning.
                    <br><br>
                    Your Account is in the process of activation by our current Driver Manager. <i>Luc Jones</i>, You may log into your account using the Username and Password given in your Sign Up Application. 
                    <br><br>
                    <b>Username:</b> <i>$EmailUsername.</i>
                    <br><br>
                    <b><i>If you have any questions, please reply to this email. We would be happy to hear from you.</i></b>
                    <br><br>
                    <b>Kind Regards</b>
                    <br><b><i>Joshua Micallef<br>
                    Chief Executive Officer - Ozzie Transport
                    ";

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

session_destroy();
//header("Location: ../../Login.php");

每次运行代码时都会出现以下错误消息:无法发送消息.Mailer错误:SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

任何人都有任何想法,我相信仍有人对此感到疑惑。

2 个答案:

答案 0 :(得分:0)

您的GoDaddy帐户应该为您提供连接到您的主机帐户所需的主机名和端口号,以便您可以使用他们的电子邮件服务器发送电子邮件。

它看起来像这样,但您必须向GoDaddy查询您帐户的确切设置。

SMTP_SERVER: smtpout.secureserver.net (or alternatively relay-hosting.secureserver.net)
SMTP_PORT: 465 //or 3535 or 80 or 25
SMTP_AUTH: true //always
SMTP_Secure: 'ssl' //only if using port 465

答案 1 :(得分:0)

对于其他人来说,今天配置仍然存在相同的问题(请注意SMTPAuth = falseSMTPAutoTLS = false

$mail->isSMTP();
$mail->Host        = 'localhost;
$mail->SMTPAuth    = false;
$mail->SMTPAutoTLS = false;
$mail->Username    = 'no-reply@example.com';
$mail->Password    = '*******';
$mail->Port        = 25;

您可以检查当前的PHPMailers docs