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

问题描述 投票:0回答:2

我目前正在为我的虚拟公司建立并运行一个网站,我一直在研究,但在任何地方都找不到答案。

当用户注册时,我希望他们收到一封电子邮件,简要介绍公司。这是我使用的代码(是的,$_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 = '[email protected]';                 // 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('[email protected]', '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");

每次我运行代码时,它都会给我以下错误消息:消息无法发送。邮件错误:SMTP connect() 失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting.

大家有什么想法吗,我相信还有人想知道这个。

php email phpmailer
2个回答
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

0
投票

对于与今天有效的配置有相同问题的其他人(请注意

SMTPAuth = false
SMTPAutoTLS = false

$mail->isSMTP();
$mail->Host        = 'localhost;
$mail->SMTPAuth    = false;
$mail->SMTPAutoTLS = false;
$mail->Username    = '[email protected]';
$mail->Password    = '*******';
$mail->Port        = 25;

您可以查看当前的 PHPMailers docs.

© www.soinside.com 2019 - 2024. All rights reserved.