如何修复未在电子邮件激活中显示的消息

时间:2019-06-13 11:18:22

标签: php phpmailer

我似乎无法在名为infinity-free的新主机中发送电子邮件激活消息。

我尝试使用phpmailer以及mail函数,但是看不到我的html内容。

$to = $email;

//sender
$from = 'pianocourse101@hotmail.com';
$fromName = 'PianoCourse101';

//email subject
$subject = 'Activate your Primer Level Membership Plan!';

//attachment file path
$file = "codexworld.pdf";

//email body content
$htmlContent = "<h1>Activate your Primer Level Membership Plan!</h1>
                                                                              <p>Dear $first $last, <br />Thank you for registering your Primer Level Membership Plan with PianoCourse101! You are receiving this e-mail because you or someone else claiming to be you has selected a Primer Level Membership Plan \n\nIf you believe that this is a mistake, please send us a ticket with the subject \"How to cancel my Primer Level Membership Plan?\" and allow at least 48 hours before receiving a reply.\n\nHowever, if this is correct, then you must activate your Primer Level Membership Plan by clicking on the link below: \n\n <a href=https://www.pianocourse101.com/activate.php?email=".htmlspecialchars($to)."&activatetoken=".htmlspecialchars($token4).">Click here to activate your Primer Level Membership Plan.</a>\n\nAlternatively, you can use the following token to manually activate your Level 3 Yearly Membership Plan by clicking on the 'Activate Membership\s Section:' \n\nToken:.$token4;
                                                                          </p>";

//header for sender info
$headers = "From: $fromName"." <".$from.">";

//boundary 
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

//headers for attachment 
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";

//multipart boundary 
$message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n";

//preparing attachment
if(!empty($file) > 0){
    if(is_file($file)){
        $message .= "--{$mime_boundary}\n";
        $fp =    @fopen($file,"rb");
        $data =  @fread($fp,filesize($file));

        @fclose($fp);
        $data = chunk_split(base64_encode($data));
        $message .= "Content-Type: application/octet-stream; name=\"".basename($file)."\"\n" .
            "Content-Description: ".basename($file)."\n" .
            "Content-Disposition: attachment;\n" . " filename=\"".basename($file)."\"; size=".filesize($file).";\n" .
            "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
    }
}
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $from;

//send email
$mail = mail($to, $subject, $message, $headers, $returnpath);

//email sending status
echo $mail?"<h1>Mail sent.</h1>":"<h1>Mail sending failed.</h1

>";

我也使用了类似内容的phpmailer,但似乎无法通过它发送。...

0 个答案:

没有答案