繁体   English   中英

使用php mail()函数的电子邮件附件-适用于gmail,但不适用于yahoo

[英]Email Attachments using php mail() function - Working for gmail but not working for yahoo

我已使用以下代码发送带有附件的邮件。 它通过gmail帐户收到了对我们来说很好的邮件,但是在yahoo帐户中没有收到该邮件。 请参考以下代码,

<?php 
    $my_file = "fb_icon_hover.png";
    $my_path = $_SERVER['DOCUMENT_ROOT']."/poc/mailChecking/";
    $my_name = "ETU";
    //$my_mail = "abibith@gmail.com";
    $my_mail = "abibith@gmail.com";
    //$my_replyto = "arul.it02@gmail.com";
    $mail_data      =   file_get_contents($_SERVER['DOCUMENT_ROOT']."/poc/mailChecking/postajob_mailcontent.html");
    $mail_data      =   str_replace('{COMPANY_NAME}',"Testing Company", $mail_data);
    $mail_data      =   str_replace('{JOB_NAME}',"Testing jobname", $mail_data);
    $mail_data      =   str_replace('{EMAIL}',"abibith@gmail.com", $mail_data);
    $mail_data      =   str_replace('{JOB_POSITION}',"Software Engineer", $mail_data);
    $mail_data      =   str_replace('{JOBTYPE}',"Programmer", $mail_data);
    $mail_data      =   str_replace('{PHONE}',"04132660407", $mail_data);
    $mail_data      =   str_replace('{ADDRESS}',"Testing Address", $mail_data);
    $mail_data      =   str_replace('{CITY}',"Testing City", $mail_data);
    $mail_data      =   str_replace('{STATE}',"Testing State", $mail_data);
    $mail_data      =   str_replace('{POSTCODE}',"605004", $mail_data);
    $mail_data      =   str_replace('{JOB_DESCRIPTION}',"This is a testing Job", $mail_data);
    /*echo "====>".$mail_data;
    die();*/
    $my_subject = "This is a mail with attachment.";
    //$my_message = "Hallo,\r\ndo you like this script? I hope it will help.\r\n\r\ngr. Olaf";
    $my_message = $mail_data;
    mail_attachment($my_file, $my_path, "abibith@gmail.com", $my_mail, $my_name, $my_subject, $my_message);
    function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $subject, $message) {
        $file = $path.$filename;
        $file_size = filesize($file);
        $handle = fopen($file, "r");
        $content = fread($handle, $file_size);
        fclose($handle);
        $content = chunk_split(base64_encode($content));
        $uid = md5(uniqid(time()));
        $name = basename($file);
        $header = "From: ".$from_name." <".$from_mail.">\r\n";
        //$header .= "Reply-To: ".$replyto."\r\n";
        $header .= "MIME-Version: 1.0\r\n";
        $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
        $header .= "This is a multi-part message in MIME format.\r\n";
        $header .= "--".$uid."\r\n";
        $header .= "Content-type:text/html; charset=iso-8859-1\r\n";
        $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
        $header .= $message."\r\n\r\n";
        $header .= "--".$uid."\r\n";
        $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
        $header .= "Content-Transfer-Encoding: base64\r\n";
        $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
        $header .= $content."\r\n\r\n";
        $header .= "--".$uid."--";
        if (mail($mailto, $subject, "", $header)) {
            echo "mail send ... OK"; // or use booleans here
        } else {
            echo "mail send ... ERROR!";
        }
    }
?>

因此,请协助我们的要求并做有需要的事情。

谢谢,

Arularasan D,

高级程序员。

$to = "myemail@mydomain.com";
$from = "Website <website@mydomain.com>";
$subject = "Test Attachment Email";

$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = "document.pdf";

//$pdfdoc is PDF generated by FPDF
$attachment = chunk_split(base64_encode($pdfdoc));

// main header
$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

// no more headers after this, we start the body! //

$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;

// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;

// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";

// send message
if (mail($to, $subject, $body, $headers)) {
    echo "mail send ... OK";
} else {
    echo "mail send ... ERROR";
}

有同样的问题。 但是后来像上例一样形成了代码(感谢Alin Purcaru),问题得以解决。 希望对你有帮助)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM