PHP发送电子邮件但不发送文本

时间:2016-04-13 05:35:27

标签: php email smtp

我正在尝试向有Verizon号码的手机发送电子邮件。这是我现在的代码

<?php require('includes/config.php');
function Send( $ToEmail, $MessageHTML, $MessageTEXT) {
  require_once ( 'classes/phpmailer/phpmailer.php' ); // Add the path as appropriate
  $Mail = new PHPMailer();
  $Mail->IsSMTP(); // Use SMTP
  $Mail->Host        = "box405.bluehost.com"; // Sets SMTP server
  $Mail->SMTPDebug   = 2; // 2 to enable SMTP debug information
  $Mail->SMTPAuth    = TRUE; // enable SMTP authentication
  $Mail->SMTPSecure  = "ssl"; //Secure conection
  $Mail->Port        = 465; // set the SMTP port
  $Mail->Username    = 'techsupport@test.com'; // SMTP fake account username
  $Mail->Password    = 'password1'; // SMTP fake account password
  $Mail->Priority    = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
  $Mail->CharSet     = 'UTF-8';
  $Mail->Encoding    = '8bit';
  $Mail->ContentType = 'text/html; charset=utf-8\r\n';
  $Mail->FromName    = 'Tech support';
  $Mail->WordWrap    = 900; // RFC 2822 Compliant for Max 998 characters per line

  $Mail->AddAddress( $ToEmail ); // To:
  $Mail->isHTML( TRUE );
  $Mail->Body    = $MessageHTML;
  $Mail->AltBody = $MessageTEXT;
  $Mail->Send();
  $Mail->SmtpClose();

  if ( $Mail->IsError() ) { // ADDED - This error checking was missing
    return FALSE;
  }
  else {
    return TRUE;
  } 
}
$stmt = $db->prepare("select phone From members where phone not like 'no';");
$stmt->execute();
$result = $stmt->fetchAll();
$ToEmail = $result[0][0];
$ToName  = 'techsupport';
$MessageHTML = "test";
$MessageTEXT = 'test';
$Send = Send( $ToEmail, $MessageHTML, $MessageTEXT);
if ( $Send ) {
  echo "<h2> Sent OK</h2>";
}
else {
  echo "<h2> ERROR</h2>";
}
die;
?>

这在我尝试发送电子邮件时起作用,但是当我使用它发送文本时它会发送但我没有收到任何内容。我知道这不是因为地址,因为我使用相同的地址,当我从gmail发送自己的文本时,它不是sql查询,因为我测试了它。我认为问题出在smtp或phpmailer中,因为我没有使用过这些问题。此外,代码运行并打印出SENT OK回声,但没有任何内容通过,也没有错误。

[编辑]要回答关于ironcito的问题,我将发送电子邮件至

phonenumber@vtext.com

我知道这很有效,因为我通过gmail使用了相同的地址。

1 个答案:

答案 0 :(得分:0)

我认为这可能是因为您在设置内容(messagehtml / messagetext)之前将内容推送到邮件(正文),这会创建一个空的电子邮件。尝试更改这些,这可能是解决方案。