电子邮件中未发送变量

时间:2016-04-19 21:17:34

标签: php email

我对此有点难过,因为我使用的是与我的另一个脚本相同的设置,并且它有效。我正在电子邮件系统中设置一个链接,供用户取消订阅。我的取消订阅脚本与我一遍又一遍使用的相同,所以我知道它有效,但是当发送电子邮件时,电子邮件不在链接中。该链接应以http://example.com/unsubscribe.php?id=ENCODED-EMAIL的形式显示在电子邮件中,但其显示为http://example.com/unsubscribe.php?id=。如果你查看我的代码,我的所有变量都会被填写并且有值,所以我很难过为什么它没有显示在电子邮件中。

应该工作的变量是$encodedTo。有什么想法吗?

require($_SERVER['DOCUMENT_ROOT']."/settings/functions.php");
require($_SERVER['DOCUMENT_ROOT'].'/php/class.phpmailer.php');
require($_SERVER['DOCUMENT_ROOT'].'/php/class.pop3.php'); 
require($_SERVER['DOCUMENT_ROOT'].'/php/class.smtp.php');

if(isset($_POST['submit'])) {

$conn = getConnected("oversizeBoard");
if(empty($_POST['company'])) {
 echo "Company Name Is Required.";
 exit();
 }
 else {
  $company = mysqli_real_escape_string($conn, $_POST['company']);
 }
if(empty($_POST['name'])) {
 echo "Contact Name Is Required.";
 exit();
 }
 else {
  $name = mysqli_real_escape_string($conn, $_POST['name']);
 }
if(empty($_POST['phone'])) {
 echo "Contact Phone Is Required.";
 exit();
 }
 else {
  $phone = mysqli_real_escape_string($conn, $_POST['phone']);
}
if(empty($_POST['date'])) {
 echo "Load Date Is Required.";
 exit();
 }
 else {
  $date = mysqli_real_escape_string($conn, $_POST['date']);
}
if(empty($_POST['start'])) {
 echo "Start Location Is Required.";
 exit();
 }
 else {
  $start = mysqli_real_escape_string($conn, $_POST['start']);
 }
if(empty($_POST['end'])) {
 echo "End Location Is Required.";
 exit();
 }
 else {
  $end = mysqli_real_escape_string($conn, $_POST['end']);
 }
if(empty($_POST['position'])) {
 echo "Position Is Required.";
 exit();
 }
 else {
  $position = mysqli_real_escape_string($conn, $_POST['position']);
 }
if(empty($_POST['rate'])) {
 echo "Job Rate Is Required.";
 exit();
 }
 else {
  $rate = mysqli_real_escape_string($conn, $_POST['rate']);
 }
if(empty($_POST['cargo'])) {
 $cargo = "Not Specified";
 }
 else {
  $cargo = mysqli_real_escape_string($conn, $_POST['cargo']);
 }
 if(empty($_POST['height'])) {
 $height = "Not Specified";
 }
 else {
  $height = mysqli_real_escape_string($conn, $_POST['height']);
 }
 if(empty($_POST['width'])) {
 $width = "Not Specified";
 }
 else {
 $width = mysqli_real_escape_string($conn, $_POST['width']);
 }
if(empty($_POST['length'])) {
 $length = "Not Specified";
 }
 else {
  $length = mysqli_real_escape_string($conn, $_POST['length']);
 }
if(empty($_POST['weight'])) {
 $weight = "Not Specified";
 }
 else {
  $weight = mysqli_real_escape_string($conn, $_POST['weight']);
 }
if(empty($_POST['miles'])) {
 $miles = "Not Specified";
 }
 else {
  $miles = mysqli_real_escape_string($conn, $_POST['miles']);
 }

$oversizeQuery = "INSERT INTO postedLoads (company, name, phone, date, start, end, position, rate, cargo, height, width, length, weight, miles)
VALUES ('$company', '$name', '$phone', '$date', '$start', '$end', '$position', '$rate', '$cargo', '$height', '$width', '$length', '$weight', '$miles')";

if (mysqli_query($conn, $oversizeQuery)) {
    echo "Your Load Has Successfully Been Posted.";
    $emailQuery = "SELECT * FROM subscriptions";
    $emailResult = mysqli_query($conn, $emailQuery);
    while ($subscriber = mysqli_fetch_array($emailResult)) {
        // Begin PHPMailer SMTP Authentication
        $mail = new PHPMailer();

        $mail->IsSMTP(); // set mailer to use SMTP
        $mail->Host = "localhost";  // specify main and backup server
        // Begin PHP Mailer Headers
        $mail->From = "loadalert@example.com";
        $mail->FromName = "Example";
        $mail->AddReplyTo("loadalert@example.com", "Example");
        $subjectDate =  date('m/d/Y h:i:s A');
        $mail->Subject = "New Load Alert! You received this alert at " . $subjectDate;
        $mail->IsHTML(true);  // set email format to HTML
        $to = $subscriber['email'];
        $mail->AddAddress($to); 
        $encodedTo = rtrim(strtr(base64_encode($to), '+/', '-_'), '=');
        date_default_timezone_set("America/Chicago");
$mail->Body = '<!DOCTYPE HTML>';
$mail->Body .= '<html>';
$mail->Body .= '<body style="padding: 0; padding-top: 20px; margin: 0; font-family: Verdana; text-align: center; background-color: #000;">';
$mail->Body .= '<div style="padding: 10px; background-color: #fff; width: 80%; margin: 10px auto; border-radius: 20px;">';
$mail->Body .= '<h1 style="text-transform: uppercase;">Hello '.$subscriber['first_name'].'!';
$mail->Body .= '<h1 style="text-transform: uppercase;">You Have Received A New Load Alert!</h1>';
$mail->Body .= '<h2>Company Details</h2>';
$mail->Body .= '<ul style="list-style: none; text-align: left; width: 80%; margin: 0 auto;">';
$mail->Body .= ' <li>Company: '. $company .'</li>';
$mail->Body .= ' <li>Company Contact: '. $name .'</li>';
$mail->Body .= ' <li>Company Phone: '. $phone .'</li>';
$mail->Body .= '</ul>';
$mail->Body .= '<h2>Load Details</h2>';
$mail->Body .= '<ul style="list-style: none; text-align: left; width: 80%; margin: 0 auto;">';
$mail->Body .= ' <li>Load Date: '. $date .'</li>';
$mail->Body .= ' <li>Pickup Location: '. $start .'</li>';
$mail->Body .= ' <li>Drop Off Location: '. $end .'</li>';
$mail->Body .= ' <li>Load Rate: '. $rate .'</li>';
$mail->Body .= ' <li> Pilot Car Position:  '. $position .'</li>';
$mail->Body .= '</ul>';
$mail->Body .= '<h2>Additional Load Details</h2>';
$mail->Body .= '<ul style="list-style: none; text-align: left; width: 80%; margin: 0 auto;">';
$mail->Body .= ' <li>Cargo: '. $cargo .'</li>';
$mail->Body .= ' <li>Height: '. $height .'</li>';
$mail->Body .= ' <li>Width: '. $width .'</li>';
$mail->Body .= ' <li>Length: '. $length .'</li>';
$mail->Body .= ' <li>Weight: '. $weight .'</li>';
$mail->Body .= ' <li>Approximate Miles: '. $miles .'</li>';
$mail->Body .= '</div>';
$mail->Body .= '<div style="background-color: #000; color: #fff; padding: 10px;">';
$mail->Body .= ' <p>You have received this e-mail because you are subscribed to your load board. <a href="http://example.com/unsubscribe.php?id="'.$encodedTo.' style="color: #ff0000; text-decoration: none; font-style: italic;">Click Here</a> to unsubscribe.</p>';
$mail->Body .= ' <p>To ensure that you receive these e-mails faster, please add us to your address book.</p>';
$mail->Body .= ' <p>Please note: There is no way to guarantee how fast you receive these e-mails. The delivery of your e-mail varies by your e-mail service provider. Please keep in mind that this load board is free, and we do our best to bring this service to you as fast as possible. Thank you.</p>';
$mail->Body .= '</div>';
$mail->Body .= '</body>';
$mail->Body .= '</html>';

    }

} 

else {
    echo "There Was An Error. Please Try Again.";
}

mysqli_close($conn);
if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
}
}
else {
 echo "You Are Not Authorized To View This Page!";
}

0 个答案:

没有答案