341127 visitors has seen the Tim-Carter.com site. Thanks!
362 visitors has seen the Tim-Carter.com site today.
 
 
Search :  
 
>>> Programming >> PHP > How to send an email with PHP? (This page has been seen 473 times)

How to send an email with PHP?

There are alot of ways to send email with PHP. I would recommend using a FREE class called PHPMailer, you can download it from http://phpmailer.codeworxtech.com/

It is very easy to use especially if you wanna send emails with file attachments.

Here is an example on how to send an email with an attachment with PHPMailer



The Code:
require("../PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();

$mail->From = "test@email.com"; //FROM EMAIL ADDRESS
$mail->FromName = "TEST EMAIL"; //FROM NAME
$mail->Host = "localhost"; //YOUR SMTP SERVER
$mail->Mailer = "smtp"; //PROTOCOL

$mailbody = "
    This is my first test email
";
$mail->Body = $mailbody;
$mail->AltBody = $mailbody;
$mail->Subject = "Test Email with attachment"
$mail->AddAddress('recipient@test.com', 'Recipientname');

$mail->AddAttachment('c:\php.rar', $name = "php.rar", $encoding = "base64",$type = "application/octet-stream");

if(!$mail->Send()){
    echo("The system was unable to send an email. Please Try Again.");
    die();
}else
    echo "Message was send";
$mail->ClearAddresses();
$mail->ClearAttachments();

Like
 
Dislike


Keywords for this article:
PHPMailer || Mail With Attachment

Post comment

Name:


Comment:

Code Language:

Code:

Here you can paste a code example. It will then be processed by SyntaxHighlighter and formatted for easier readability.
Please remember to select the correct Code Language in the select above so the SyntaxHighlighter can highlight the code properly.




Code:

Please enter the code you see above

What is 6 + 9 =

Submit Comment


No one has commented on this page yet. You could be the first.


Advertisement by Google