我正在使用下面的代码作为我正在处理的网站的邮件列表,并且它在我的本地主机上使用我的凭据正常工作,并在其他服务器上使用其他一些凭据给我。
<?php
if(isset($_POST['submit']))
{
require("class.phpmailer.php");
$mail = new PHPMailer();
$query = "SELECT * FROM mailing_list";
$result = mysqli_query($connect, $query)
or die('Error querying the database!');
$mail->IsSMTP();
$mail->Host= "smtp";
$mail->Username= "some email address was given to me";
$mail->Password= "password";
$mail->SMTPAuth= true;
$mail->SMTPSecure = 'tls';
$mail->From ="some email address was given to me";
$mail->FromName ="CSCA";
while($row = mysqli_fetch_array($result))
{
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$to = $row['email'];
$mail->ClearAddresses();
$mail->AddAddress($to);
$mail->Subject= $_POST['subject'];
$mail->Body = "Dear $first_name $last_name,\n" . $_POST['body'];
$mail->WordWrap = 50;
if(!$mail->Send())
{
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
现在,当我在同一网站的联系我们页面中使用以下代码时,使用我自己的凭据可以很好地使用我的本地主机,但它不能在我上面使用的其他服务器上运行。我在垃圾邮件中收到了一条邮件,邮件传递失败了#39;我不知道如何使用相同的凭据发送邮件,但您无法收到!我的意思是使用相同的服务器和相同的凭据,您的邮件列表工作正常,但联系我们表单给出错误。有办法解决这个问题吗?
提前致谢!
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$name = $_REQUEST['name'];
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$mail->IsSMTP();
$mail->Host="smtp";
$mail->Username="some email address was given to me";
$mail->Password="password";
$mail->SMTPAuth=true;
$mail->SMTPSecure = 'tls';
$mail->From =$email;
$mail->FromName =$name;
$mail->AddAddress("some email address was given to me", "Some name");
$mail->IsHTML(true);
$mail->Subject = "You have received feedback from your website!";
$mail->Body = $message;
$mail->AltBody = $message;
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}