onlinecode

Send PHP mail with Attachment with script and function

Send PHP mail with Attachment with script and function

In this post we will show you Send PHP mail with Attachment, This custom function or PHP mail attachment script is in a position to send an obvious text email message along with one attachment file. The attachment file has got to be uploaded 1st otherwise you will use a file that already exists on your internet server. There ar far better and a lot of advanced PHP scripts on the web, however I hope this instance can assist you to know, however it’s potential to send associate email message and attachment by victimisation some PHP code.

Send PHP mail with Attachment function mail() operate

PHP mail attachmentThe mail() operate doesn’t support attachment or hypertext markup language mail by default. you wish to use completely different headers and MIME mail components to form this potential. several shared hosting suppliers doesn’t enable the usage of this operate and it’d be disabled.

Normally you may pass 3 values to the mail() operate and some headers. within the example below I skip price|the worth} for the message value, as a result of the message is outlined as a MIME half along with the attachment.

Send PHP mail with Attachment function AddAttachment() operate

Synopsis

require_once ‘Mail/mime.php’;

// set addAttachment function
boolean addAttachment ( string $file , string $c_type = 'application/octet-stream' , string $name = '' , boolean $isfile = true , string $encoding = 'base64' , string $disposition = 'attachment' , string $charset = '' , string $language = '' , string $location = '' , string $n_encoding = null , string $f_encoding = null , string $description = '' , string $h_charset = null )

Description for Send PHP mail with Attachment

Adds associate attachment to a message.

Parameter for Send PHP mail with Attachment

Return valuses for Send PHP mail with Attachment

boolean – Returns TRUE on success, PEAR_Error on failure

// Send PHP mail with Attachment
require 'class.phpmailer.php';

$mail = new PHPMailer;

$seller_name = "onlinecode test";
$temp = "temp/onlinecode.pdf";
$poorder = "purchase-order-agreement.pdf";

$seller_email_id = "ingo@onlinecode";
$mailto = $seller_email_id;

$subject = "Notification of order agreement";
$bodytext = "<br> Hello<br> <b>".$seller_name."</b>,<br>This Order has been sent to the Seller for their review. You will be notified when their review has been completed. and this test for Send PHP mail with Attachment<br> Regard <br> <b>onlinecode Team</b>  ";

$mail->IsSMTP();                                      // Set mailer to use SMTP
//$mail->SMTPSecure = 'tls';
$mail->Host = 'ssl://smtp.gmail.com';                // Specify main and backup server
$mail->Port = 465;
$mail->SMTPDebug = 1;                                  // Set the SMTP port
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'onlinecode12365@gmail.com';                // SMTP username
$mail->Password = 'ADD-YOUR-PASSWORD';                  // SMTP password
//$mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted
$mail->AddAttachment($temp, $poorder);
$mail->From = 'onlinecode@onlinecode';
$mail->FromName = 'onlinecode Team';// frome name
$mail->AddAddress($mailto , $seller_name);  // Add a recipient  to name
//$mail->AddAddress($mailto );               // Name is optional

$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = $subject;
$mail->Body    = $bodytext;

if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
else
{
echo 'Message has been sent';
}

Exit mobile version