Sunday, October 20, 2013

Using PHP Mailer Class to send mails from Localhost (Without making you website Live)

Hiiiiii, We all know that its common practice to send mails in our PHP website and you can perform this mail sending task by PHP  mail() function , but the problem with this function is that it works only when you site is live and you have put your website on some web server. But what when you have to test mail sending your localhost in your local machine at the time of developing. You can solve this problem by using PHP mailer class in your website to send mails from your local host .

To use PHP mailer class in your code , you have to made some changes in php.in to make PHP mailer class work and to see the changes, CLICK HERE .

PHP mailer class


You can download the complete code required for this tutorial FROM HERE or you can download the code files except PHP mailer class from below :

CODE FILES :

example.php :


<?php
$message = "Your message body" ;
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->Username = "youremail@gmail.com"; // my email which I hope to receive the data inputed on the field
$mail->Password = "password";

$email="abc@example.com"; // email which you want to show other than original sender
$mail->SetFrom($email, 'Test Mail'); // name of this another email mentioned above
$address = "recepient@example.com"; // recepient address
$mail->AddAddress($address, "Fine Design"); // Name of the Recepeint
$mail->Subject = "Fine Design - Avise me!"; // Subject
$mail->Body = $message;

if(!$mail->Send()) {
echo'nt sent';
echo'<span><b>';
echo $mail->ErrorInfo;
echo '</span></b>';

echo'</div>';
} else {
header("Location: ./thank-you.php");
}
?>

thank-you.php :

<?php
// Process the submitted data
echo "<div style='text-align:center;'><h2>Thank you for Contacting Us!</h2></div> ";
$t2lpostData = $_POST;
echo "</div>";
?>


Hope you like this post……..Please Comment…………!!!!!!!!!


Tags:

0 Responses to “Using PHP Mailer Class to send mails from Localhost (Without making you website Live)”

Post a Comment

© 2013 MyCodeStock. All rights reserved.
Designed by SpicyTricks