jnel Posted April 27, 2022 Share Posted April 27, 2022 (edited) Good day, i have written code to send mail to email with an pdf attachment.The pdf is receive when it is send to a gmail account,but when it is send to an exchange mail account,it just looks as in the picture.A lot of nonsens. my statement.pdf is in the folder mainfolder/fpdf i have tried various options,but just can not get this to work.Any help is appreciated. this is the code i am using $filename="statement.pdf"; $subject= "Statement"; $recipient = "email1@gmail.com,email2@namibia.com.na"; $email="email@snappy.com"; //documentation for Output method here: http://www.fpdf.org/en/doc/output.htm $attach_pdf_multipart = chunk_split( base64_encode( $pdf->Output( $filename, 'S' ) ) ); //define the receiver of the email $to = "email1@gmail.com,email2@namibia.com.na"; //define the subject of the email $subject = 'Statement'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: email@snappy.com\r\nReply-To: email@snappy.com"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; $headers .= "\r\n"; $msg .= "Content-Type: application/octet-stream; name=\"statement.pdf\"\r\n"; $msg .= "\r\n"; $msg .= "Content-Transfer-Encoding: base64\r\n"; $msg .= "Content-Disposition: attachment\r\n"; $msg .= $attach_pdf_multipart . "\r\n"; $msg .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"; $msg .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $msg .= "<p>This is text message from shohag</p>\r\n\r\n"; global $message; $message = ''; $mail_sent = @mail( $to, $subject, $msg, $headers ); //@mail( $to1, $subject, $msg, $headers ); if(!empty($mail_sent)): echo "Mail Has Been Send"; $message = "Statement sent succuessfully"; else: echo "bad-----"; $message = "Error occured. Please try again."; endif; Edited April 27, 2022 by jnel want to follow Quote Link to comment https://forums.phpfreaks.com/topic/314735-exchange-email/ Share on other sites More sharing options...
ginerjm Posted April 27, 2022 Share Posted April 27, 2022 1 - please post all code using the <> icon above. 2 - strongly suggest using PHPMailer as your mail tool It will make what you are trying to do soooo much easier.[ 3 - please us the <> tool above to post your code. (Get the point?) Quote Link to comment https://forums.phpfreaks.com/topic/314735-exchange-email/#findComment-1595747 Share on other sites More sharing options...
jnel Posted April 27, 2022 Author Share Posted April 27, 2022 i tried to use phpmailer,but can not get it to work.If you can posisble give me a small sample with an attachment,i would really appreciate it. I created a folder phpmail and copied the phpmailer.php file in that folder. then created a test script,but i can not get it to work Quote Link to comment https://forums.phpfreaks.com/topic/314735-exchange-email/#findComment-1595749 Share on other sites More sharing options...
maxxd Posted April 27, 2022 Share Posted April 27, 2022 If you're copying phpmailer.php into a directory manually you're not using the correct thing (or it's not being used correctly). PHPMailer is installed via composer and very well documented. Quote Link to comment https://forums.phpfreaks.com/topic/314735-exchange-email/#findComment-1595750 Share on other sites More sharing options...
ginerjm Posted April 27, 2022 Share Posted April 27, 2022 Did you read the instructions when you downloaded it? It is really very simple but, like all things involved with coding, one has to read the instructions. Quote Link to comment https://forums.phpfreaks.com/topic/314735-exchange-email/#findComment-1595751 Share on other sites More sharing options...
jnel Posted April 27, 2022 Author Share Posted April 27, 2022 do i need php on my machine to install the phpmailer with the composer? On this moment i do not have it. The instructions sayd you do not need the composer,then you have to manually include the files in you code.Which i did.But when i run it,i just get to nr 4. It do not want to add the address. use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; echo "2"; require('./src/PHPMailer.php'); echo "3"; require('./src/Exception.php'); echo "na require"; $email= new PHPMailer(); echo "4"; $mail->setFrom('darth@empire.com', 'Darth Vader'); echo "5"; $mail->send(); echo "after send"; Quote Link to comment https://forums.phpfreaks.com/topic/314735-exchange-email/#findComment-1595756 Share on other sites More sharing options...
Barand Posted April 27, 2022 Share Posted April 27, 2022 Paying attention to the spelling would give it more of a chance. $email= new PHPMailer(); ^ echo "4"; $mail->setFrom('darth@empire.com', 'Darth Vader'); ^ Quote Link to comment https://forums.phpfreaks.com/topic/314735-exchange-email/#findComment-1595757 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.