regarding email with attachment in php

后端 未结 1 1404
悲哀的现实
悲哀的现实 2021-01-25 08:43

Can any one hel me?? I am trying to send an email with attachment it sends the email but the email is send in encoded format I think the problem is with headers can any one give

相关标签:
1条回答
  • 2021-01-25 09:00

    You can use PHPMailer http://code.google.com/a/apache-extras.org/p/phpmailer/

    Dowload Link : http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/detail?name=PHPMailer_5.2.1.zip&can=2&q=

    $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
    
    try {
      $mail->AddReplyTo('name@yourdomain.com', 'First Last');
      $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
      $mail->SetFrom('name@yourdomain.com', 'First Last');
      $mail->AddReplyTo('name@yourdomain.com', 'First Last');
      $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
      $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
      $mail->MsgHTML(file_get_contents('contents.html'));
      $mail->AddAttachment('images/phpmailer.gif');      // attachment
      $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
      $mail->Send();
      echo "Message Sent OK</p>\n";
    } catch (phpmailerException $e) {
      echo $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
      echo $e->getMessage(); //Boring error messages from anything else!
    }
    

    Thanks

    :)

    0 讨论(0)
提交回复
热议问题