Many PHP programmers facing this issue and hitting same wall which is already hitted.
PHP itself provides the mail() function to send emails. In this article I will show you the options of sending email using PHP language.
If you are using linux or windows hosting service for running the PHP application. PHP mail() function uses the sendmail mail server to send emails.
If sendmail mail server is configured and running on linux server then only mail() function is able to send the emails.
First we will talk about mail() function. You can pass the following parameters to mail function.
mail(to,subject,message,headers,parameters)
Sample code as follows:
<?php $to = "support@wordpressapi.com/files/, wordpressapi@gmail.com"; $subject = "Test mail"; $message = "This is a simple email message. <br> this is seond line."; $from = "some@example.com, wordpressapi@gmail.com"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: $from"; $headers .= 'Cc: test@test1.com' . "\r\n"; $headers .= 'Bcc: test2@test1.com' . "\r\n"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?>
If sendmail mail server is not configured on your server, mostly with windows server then there is issue.
But you can send email using anothere PHP programm called PHPmailer.
you can download the PHPmailer from following URL:
http://sourceforge.net/projects/phpmailer/
Download first PHPmailer and extract the phpmailer folder and in that folder you will find the following three files.
1. class.phpmailer.php
2. class.pop3.php
3. class.smtp.php
copy and paste the following files to your PHP application. and use the following code in case of use POP email
<?php
function sendmail_wordpressapi($to,$from,$subject,$body,$id){
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
include_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "wordpressapi.com/files/"; // SMTP server
$mail->From = $from;
$mail->FromName = $from;
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress($to, $to);
if(!$mail->Send()) {
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "WORDPRESSAPI@gmail.com"; // GMAIL username
$mail->Password = "YOURPASSWORD"; // GMAIL password
$mail->AddReplyTo("smtp.production@gmail.com","wordpressapi");
$mail->From = "support@wordpressapi.com/files/";
$mail->FromName = "SMTP EMAIL-wordpressapi";
$mail->Subject = "email server is having some issue";
$mail->Body = "Hi,<br>email server is having some issue,<br> check this out"; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress("support@wordpressapi.com/files/", "support-wordpressapi");
$mail->IsHTML(true); // send as HTML
$mail->Send();
} else {
echo "Message sent!";
}
}
?>
I created above function in this function I am using SMTP mail function for sending email but in case mail is not going using SMTP details.
you can also send emails using your gmail account details. you can edit or use this function as your requirement.
You can pass following parameters to sendmail_wordpressapi function:
sendmail_wordpressapi($to,$from,$subject,$body,$id);
You can send email to multiple email addresses. I am sure using above code sending emails through PHP is very easy. If you have any quries..write to me.
Incoming search terms:
- wordpress how to sending email
- automatic send email api in php
- wordpress php send mail()
- sending mail using php code download free
- send mail in php with api
- send email with php through wordpress
- php sendmail api
- php mail API
- passing message in mail api Php
- linux sendmail php example
- how we can send mail using wordpress
- how to send mail in php with other languages
- how to send mail from wordpress with php file
- facebook send mail php api
- wordpress using php mail






Pingback: How to send emails using PHP language | wordpressapi.com | Drakz Free Online Service
I need some advice for my blog….I like your layout. Can you help me? 6 7 1
I like the layout of your blog and I’m going to do the same thing for mine. Do you have any tips? Please PM ME on yahoo @ AmandaLovesYou702 9 6 7
Just want to say what a great blog you got here!
I’ve been around for quite a lot of time, but finally decided to show my appreciation of your work!
Thumbs up, and keep it going!
Cheers
Christian, iwspo.net
Your blog is so informative ¡ keep up the good work!!!!
shares use a wonderful website decent Gives thank you for the efforts to help people
Great blog post.Really looking forward to read more.
It’s an interesting view for sure and I appreciate it so this is a little something for all…
Smith & Wesson: The original point and click interface.
To send HTML mail in PHP, you need to use some additional headers. Below is the code to send HTML mail in PHP.
$to = “recipient@domain.com“;
$subject= “Subject of email”;
$message= “This is HTML mail.”;
$fromName = “Name of the sender”;
$fromEmail = “sender@domain.com“;
// To send HTML mail, the Content-type header must be set
$headers = “MIME-Version: 1.0? . “\r\n”;
$headers .= “Content-type: text/html; charset=iso-8859-1? . “\r\n”;
// Additional headers
$headers .=”From: $fromName ”.”\r\n”;
//Mail function
mail($to, $subject, $message, $headers);
Source:
http://http://phphelp.co/2012/05/03/how-to-send-html-mail-in-php//
OR
http://http://addr.pk/a1c4