Wednesday, November 26, 2014

how to configure xampp to send mail in php?




In order to send mail, you have to make some changes in your files if you are using XAMPP. Configure two files, first one is C:\xampp\php\php.ini and the second one is c:\xampp\sendmail\sendmail.ini

In C:\xampp\php\php.ini find extension=php_openssl.dll and remove the semicolon from the beginning of that line to make SSL working for mailing sites like gmail for your localhost.

In php.ini file find [mail function] and change

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"


Now Open C:\xampp\sendmail\sendmail.ini. Replace all the existing code in sendmail.ini with following code

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=gmail-id@gmail.com
auth_password=gmail-password
force_sender=gmail-id@gmail.com

Note: Replace gmail-id and gmail-password in above code with yours.

Note: If you are unable to send mail using your gmail accout then you need to make some changes in your gmail account setting like change Access for less secure apps must be enable. Login into your gmail accout and follow the link Gmail setting for less secure apps to configure your gmail account setting.

Click here to get code to send mail using php

how to send mail in php from localhost?




In previous chapter you got idea to configure your XAMPP. If you've configured then move to code to send mail and if not then configure at first. click here to configure.
Now it's time to write code in order to send mail. Below is the code to send mail using php:

<?php

$to = "your-gmail-id@gmail.com";
$subject = "HTML email using PHP";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This is an HTML Email send using php mail function.</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Avnish</td>
<td>alok</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <your-gmail-id@gmail.com>' . "\r\n";

$chk=mail($to,$subject,$message,$headers);
if($chk)
echo "success";
else
echo "fail";
?>
 

Monday, November 24, 2014

Write For Us






CS HOT TOPICS is open for guest posts and blog advertisement now. If you want to write for us on computer programming and its related technologies, kindly contact us at avnishalok.se@gmail.com.
After getting your post we'll review it and if it looks good then we'll publish your post within 2 working days. Below are the list of topics for which you can write for us:

  • Computer languages and its related technologies
  • Mobile technology
  • Technical support