How to send e-mail with Attachment with PHP Scripts
Jon Moffet
Here's how to send an email with attachment using PHP scripts (via PHPMailer class).
CODE:
-
require("phpmailer/class.phpmailer.php");
-
//****
-
//PLEASE CHANGE THE SETTINGS HERE !!!!
-
//change settings here
-
$your_email = "info@example.com";
-
$your_smtp = "mail.example.com";
-
$your_smtp_user = "info@example.com";
-
$your_smtp_pass = "example_password";
-
$your_website = "http://example.com";
-
//****
-
//get contact form details
-
$name = $_POST['name'];
-
$email = $_POST['email'];
-
$url = $_POST['url'];
-
$comments = $_POST['comments'];
-
$response="Name: $name\nContents:\n$comments\n";
-
$mail = new PHPmailer();
-
$mail = $mail->SetLanguage("en", "phpmailer/language");
-
$mail->From = $your_email;
-
$mail->FromName = $your_website;
-
$mail->Host = $your_smtp;
-
$mail->Mailer = "smtp";
-
$mail->Password = $your_smtp_pass;
-
$mail->Username = $your_smtp_user;
-
$mail->Subject = "$your_website feedback";
-
$mail->SMTPAuth = "true";
-
$mail->Body = $response;
-
$mail->AddAddress($your_email,"$your_website admin");
-
$mail->AddReplyTo($email,$name);
-
-
$mail->AddAttachment("picture.png","picture");
-
-
echo "<p>Thanks for your feedback, <em>$name</em>! We will contact you soon!</p>";
-
if (!$mail->Send()) {
-
echo "<p>There was an error in sending mail, please try again at a later time</p>";
-
}
-
$mail->ClearAddresses();
-
$mail->ClearAttachments();
the key function of this script is $mail->AddAttachment("picture.png","picture.png");, where you can add any file as email attachments from your script.
Hopefully this example will help you to create a useful and flexible mail sending php scripts
Tags: php, email, emails, mail, e-mails, programming, php scripts, scripts
Posted in Uncategorized |








June 5th, 2007 at 5:04 am
Hi Jim. Photos i received. Thanks
June 6th, 2007 at 3:23 pm
August 1st, 2007 at 1:34 am
Hello! Good Site! Thanks you! qqkxlwipnlr
November 13th, 2007 at 6:36 am
I’ve never been all that big a fan of Hyundai and it could be because of the sour taste left from the Hyundai Pony so many years ago. Quality is definitely improving in South Korea and people are quite pleased with the 2007/2008 Tiburon. We’ve seen some heavily camouflaged pictures of its RWD replacement, but when there’s that much tarp, it’s hard to decide whether you like the new car or not. It’s time to strip away all that camouflage and see what the next generation Hyundai Tiburon replacement is all about. Here is the Hyundai Coupe in…http://super-blog-here.com/