Jump to content

Exchange email


jnel

Recommended Posts

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;
        

 

error.PNG

Edited by jnel
want to follow
Link to comment
Share on other sites

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?)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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";

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.