PHP email with attachment help

8 replies
I am able to send email in plain text format but I want to know how can i send email with an attachment using php script?

Any help regarding this will be appreciated
#attachment #email #php
  • Profile picture of the author telewarrior
    Hi,

    Here is an example script that should do the trick. It is dependent on Pear being installed, but the basic process is in there.

    Also, in the Php docs online, there are a great number of examples in the comments for a related function. Search for "Send Multi attachment email" down in the comments in this Php manual page on the mail function (yes, there is an app for that :p) for a contributed example.

    Hope it helps,

    Brett
    {{ DiscussionBoard.errors[5052612].message }}
  • Profile picture of the author academysigma
    If you want a browser interface to send emails then try phpmailer class.
    Create a form and store collected data into variables.

    You will have to include an upload functionality into this form, so the files are uploaded before running the script below.


    require_once('class.phpmailer.php');

    $mail = new PHPMailer();

    $body = "Your body text in HTML"
    $body = eregi_replace("[\]",'',$body);

    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host = "mail.yourdomain.com";

    $mail->SMTPAuth = true; // enable SMTP
    $mail->Host = "
    mail.yourdomain.com"; // SMTP server
    $mail->Port = 26; // SMTP port (26 is for gmail servers)
    $mail->Username = "login"; // SMTP account email address login
    $mail->Password = "yourpassword"; // SMTP account password

    $mail->SetFrom("you@yourdomain.com","Sender Name");
    $mail->AddReplyTo("
    you@yourdomain.com","Sender Name");

    $mail->Subject = "Subject Line";
    $mail->Body = $body;

    $mail->AddAddress("recipient@domain.com", "Joe");

    $mail->AddAttachment("attachment.pdf"); // attachment
    $mail->AddAttachment("attachement.gif"); // attachment

    if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
    echo "Message sent!";
    }
    {{ DiscussionBoard.errors[5053930].message }}
    • Profile picture of the author seomagic
      Originally Posted by academysigma View Post

      If you want a browser interface to send emails then try phpmailer class.
      Create a form and store collected data into variables.

      You will have to include an upload functionality into this form, so the files are uploaded before running the script below.


      require_once('class.phpmailer.php');

      = new PHPMailer();

      = "Your body text in HTML"
      = eregi_replace("[]",'',);

      (); // telling the class to use SMTP
      = "mail.yourdomain.com";

      = true; // enable SMTP
      = "
      mail.yourdomain.com"; // SMTP server
      = 26; // SMTP port (26 is for gmail servers)
      = "login"; // SMTP account email address login
      = "yourpassword"; // SMTP account password

      ("you@yourdomain.com","Sender Name");
      ("
      you@yourdomain.com","Sender Name");

      = "Subject Line";
      = ;

      ("recipient@domain.com", "Joe");

      ("attachment.pdf"); // attachment
      ("attachement.gif"); // attachment

      if(!()) {
      echo "Mailer Error: " . ;
      } else {
      echo "Message sent!";
      }
      Thank you for the code i have done it now, can anyone get in more details and can tell me how can i use ajax to show progress in it?
      {{ DiscussionBoard.errors[5061595].message }}
      • Profile picture of the author oyemomodu
        can any show me how to design a mailer?
        {{ DiscussionBoard.errors[6963476].message }}
  • Profile picture of the author lordspace
    using jQuery ....

    Code:
    $.post('contact.php', function(data) {
      $('.result').html(data);
    });
    Signature

    Are you using WordPress? Have you tried qSandbox yet?

    {{ DiscussionBoard.errors[6972625].message }}
  • Profile picture of the author edbarnes
    The first results on Google :
    finalwebsites.com/forums/topic/php-e-mail-attachment-script
    webcheatsheet.com/php/send_email_text_html_attachment.php
    php.net/manual/en/function.mail.phptexelate.co.uk/blog/send-email-attachment-with-php/
    {{ DiscussionBoard.errors[6982037].message }}
  • Profile picture of the author ababuobana
    Visit PHP manual for function "mail" . It has lots of other options . Google "PHP manual mail", I cannot send links in this forum yet
    {{ DiscussionBoard.errors[6984455].message }}

Trending Topics