|
| | |
| Main » 2012 » November » 6 » HOW TO SEND SMTP AUTHENTICATED MAIL
9:44 PM HOW TO SEND SMTP AUTHENTICATED MAIL |
HOW TO SEND SMTP AUTHENTICATED MAIL
First download and unpack the files in your root directory ,the mail attachment zip pack from our media fire cloud storage follow the link: http://www.mediafire.com/?jz2yr1pws9mr297 now we are posting the following example : Example 1: send a simple smtp authenticated mail with all available options IsSMTP(); // telling the class to use SMTP try { $mail->Host = "mail.yourdomain.com"; // SMTP server $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) $mail->SMTPAuth = true; // enable SMTP authentication $mail->Host = "mail.yourdomain.com"; // sets the SMTP server $mail->Port = 26; // set the SMTP port for the GMAIL server $mail->Username = "yourname@yourdomain"; // SMTP account username $mail->Password = "yourpassword"; // SMTP account password $mail->AddAddress('whoto@otherdomain.com', 'John Doe'); $mail->SetFrom('name@yourdomain.com', 'First Last'); $mail->AddReplyTo('name@yourdomain.com', 'First Last'); $mail->Subject = 'PHPMailer Test Subject via mail(), advanced'; $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically $mail->MsgHTML(file_get_contents('contents.html')); $mail->AddAttachment('images/phpmailer.gif'); // attachment $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment $mail->Send(); echo "Message Sent OK \n"; } catch (phpmailerException $e) { echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { echo $e->getMessage(); //Boring error messages from anything else! } ?> example2: send a mail from database IsSMTP(); // telling the class to use SMTP $mail->Host = "smtp1.site.com;smtp2.site.com"; $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPKeepAlive = true; // SMTP connection will not close after each email sent $mail->Host = "mail.yourdomain.com"; // sets the SMTP server $mail->Port = 26; // set the SMTP port for the GMAIL server $mail->Username = "yourname@yourdomain"; // SMTP account username $mail->Password = "yourpassword"; // SMTP account password $mail->SetFrom('list@mydomain.com', 'List manager'); $mail->AddReplyTo('list@mydomain.com', 'List manager'); $mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication"; @MYSQL_CONNECT("localhost","root","password"); @mysql_select_db("my_company"); $query = "SELECT full_name, email, photo FROM employee WHERE id=$id"; $result = @MYSQL_QUERY($query); while ($row = mysql_fetch_array ($result)) { $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $mail->AddAddress($row["email"], $row["full_name"]); $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg"); if(!$mail->Send()) { echo "Mailer Error (" . str_replace("@", "@", $row["email"]) . ') ' . $mail->ErrorInfo . ' '; } else { echo "Message sent to :" . $row["full_name"] . ' (' . str_replace("@", "@", $row["email"]) . ') '; } // Clear all addresses and attachments for next loop $mail->ClearAddresses(); $mail->ClearAttachments(); } ?>
|
Category: Web Development |
Views: 332 |
Added by: admin-priyank
| Rating: 5.0/1 |
| |
| | |
|
Calendar |
| « November 2012 » | Su | Mo | Tu | We | Th | Fr | Sa | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| |
|
Our poll |
| | |
|
Statistics |
|
Total online: 1 Guests: 1 Users: 0 | |
|
|