-1

I want to send an attachment with email, is it possible? My client has registered email with google. This is what I have so far:

$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$txt,$headers);
?>
Rasclatt
  • 12,498
  • 3
  • 25
  • 33

2 Answers2

0

Use PHPMailer class,

 include 'PHPMailer.php';
    $email = new PHPMailer();
    $email->From      = 'you@example.com';
    $email->FromName  = 'Your Name';
    $email->Subject   = 'Message Subject';
    $email->Body      = $bodytext;
    $email->AddAddress( 'destinationaddress@example.com' );

$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';

$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );

return $email->Send();

Download PHPMailer class,

https://github.com/PHPMailer/PHPMailer
US-1234
  • 1,519
  • 4
  • 24
  • 61
0

You can use PHPMailer php library to send email..
http://phpmailer.worxware.com/

        <?php 
        require "[YOUR PATH TO PHPMAILER LIB]/class.phpmailer.php";
        require "[YOUR PATH TO PHPMAILER LIB]/class.smtp.php";
    $mail = new PHPMailer;

            $mail->isSMTP(); // Set mailer to use SMTP

            $mail->Host = 'mtp.host.com'; // Specify main SMTP servers
            $mail->SMTPAuth = true; // Enable SMTP authentication
            $mail->Username = '[email address to send email]'; // SMTP username
            $mail->Password = '[above email password]'; // SMTP password
            $mail->SMTPSecure = 'encryption type'; // Enable TLS encryption, `ssl` also accepted
            $mail->Port = [SMTP PORT]; // TCP port to connect to

            $mail->From = '[FROM EMAIL]';
            $mail->FromName = '[FROM NAME]';
            $mail->addAddress([recipient email address], [recipient name]);    // Add a recipient
            $mail->addReplyTo(reply@example.com, reply);
            $mail->addAttachment([attachment path], [attachment name]);// name
            $mail->isHTML(true); // Set email format to HTML
            $mail->Subject = $subject;
            $mail->Body    = $body;
            $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
            $mail->send();
?>