发送电子邮件的使用GoDaddy主机与PHPMailer?

ovfsdjhp  于 2023-01-16  发布在  PHP
关注(0)|答案(2)|浏览(213)

我目前正在为我的虚拟公司建立和运行一个网站,我一直在研究,不能找到这个问题的答案。
当用户注册时,我希望他们收到一封电子邮件,简要介绍公司。下面是我使用的代码(是的,$_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");

每次我运行代码时,它都给我以下错误消息:无法发送邮件。邮件程序错误:SMTP连接()失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
任何人有任何想法,我相信仍然有人想知道这一点。

dzhpxtsq

dzhpxtsq1#

您的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
lo8azlld

lo8azlld2#

对于其他具有与当前配置相同问题的配置(请注意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文档。

相关问题