Send attachments with PHP Mail()?

前端 未结 14 2445
北恋
北恋 2020-11-21 04:46

I need to send a pdf with mail, is it possible?

$to = \"xxx\";
$subject = \"Subject\" ;
$message = \'Example message with html\';
$header         


        
14条回答
  •  终归单人心
    2020-11-21 05:04

    HTML Code:

    PHP Code:


    $sender_name ,contacted you through your website and the details are as below:

    Name : $sender_name
    Contact Number : $contact
    Email : $sender_mail
    Subject : $mail_subject
    Message : $message."; //Reply Content $reply_subject = "Subject seen on sender's mail"; $reply_body = "Hello $sender_name,
    \t Thank you for filling the contact form. We will revert back to you shortly.

    This is an auto generated mail sent from our Mail Server.
    Please do not reply to this mail.
    Regards
    $server_name"; //#############################DO NOT CHANGE ANYTHING BELOW THIS LINE############################# $filename= $_FILES[$input_file]['name']; $file = chunk_split(base64_encode(file_get_contents($_FILES[$input_file]['tmp_name']))); $uid = md5(uniqid(time())); //Sending mail to Server $retval = mail($server_mail, $main_subject, "--$uid\r\nContent-type:text/html; charset=iso-8859-1\r\nContent-Transfer-Encoding: 7bit\r\n\r\n $main_body \r\n\r\n--$uid\r\nContent-Type: application/octet-stream; name=\"$filename\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"$filename\"\r\n\r\n$file\r\n\r\n--$uid--", "From: $sender_name <$sender_mail>\r\nReply-To: $sender_mail\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"$uid\"\r\n\r\n"); //Sending mail to Sender $retval = mail($sender_mail, $reply_subject, $reply_body , "From: $server_name<$server_mail>\r\nMIME-Version: 1.0\r\nContent-type: text/html\r\n"); //#############################DO NOT CHANGE ANYTHING ABOVE THIS LINE############################# //Output if ($retval == true) { echo "Message sent successfully..."; echo ""; } else { echo "Error
    "; echo "Message could not be sent...Try again later"; echo ""; } }else{ echo "Error
    "; echo "File Not Found"; } }else{ echo "Error
    "; echo "Unauthorised Access"; }

提交回复
热议问题