如何使以下邮件功能在localhost上运行

时间:2018-12-11 01:18:06

标签: php email localhost

直到最近,以下邮件功能一直运行良好。我发现问题可能出在hotmail上,他们以某种方式阻止了它,我尝试将其更改为我的gmail帐户,该帐户似乎可以在实时服务器上使用,但现在可以在本地主机上使用。我必须在这里更改任何内容吗?

//recipient
$to = $email;

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

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

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

//email body content
$htmlContent = "<h1>Activate your Level 1 Monthly Membership Plan!</h1>
    <p>Thank you for registering your Level 1 Monthly Membership Plan with PianoCourse101! You are receiving this e-mail because you or someone else claiming to be you has bought a Level 1 Monthly Membership Plan \n\nIf you believe that this is a mistake, please send us a ticket with the subject \"How to cancel my Level 1 Monthly Membership Plan?\" and allow at least 48 hours before receiving a reply.\n\nHowever, if this is correct, then you must activate your Level 1 Monthly Membership Plan by clicking on the link below: \n\n <a href=http://localhost/loginsystem/includes/activatepremium.php?email=".htmlspecialchars($to)."&activatetoken=".htmlspecialchars($token).">Click here to activate your Level 1 Monthly Membership Plan</a>;
</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); 

0 个答案:

没有答案