Send Email with SMTP and PHP Mailer
In this tutorial we have a simple script which send email through SMTP (Send Mail Transfer protocol) with PHP Mailer. We need phpmailer library and bellow given code.
[wpdm_file id=6]
PHP Code
Simple PHP file
<?php require_once('PHPMailer_v5.1/class.phpmailer.php'); //library added in download source. $msg = 'Hello World'; $subj = 'test mail message'; $to = '[email protected]'; $from = '[email protected]'; $name = 'My Name'; echo smtpmailer($to,$from, $name ,$subj, $msg); function smtpmailer($to, $from, $from_name = 'Example.com', $subject, $body, $is_gmail = true) { global $error; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; if($is_gmail) { $mail->SMTPSecure = 'ssl'; $mail->Host = 'smtp.gmail.com'; $mail->Port = 465; $mail->Username = '[email protected]'; $mail->Password = '*******'; } else { $mail->Host = 'smtp.mail.google.com'; $mail->Username = '[email protected]'; $mail->Password = '******'; } $mail->IsHTML(true); $mail->From="[email protected]"; $mail->FromName="Example.com"; $mail->Sender=$from; // indicates ReturnPath header $mail->AddReplyTo($from, $from_name); // indicates ReplyTo headers $mail->AddCC('[email protected]', 'CC: to site.com'); $mail->Subject = $subject; $mail->Body = $body; $mail->AddAddress($to); if(!$mail->Send()) { $error = 'Mail error: '.$mail->ErrorInfo; return true; } else { $error = 'Message sent!'; return false; } } ?>
Tutorial Categories:
This is not working!!
Getting This error comes
Fatal error: Class ‘SMTP’ not found in C:wampwwwFBSTOREphpmailerPHPclass.phpmailer.php on line 1147
Download the code and use it as it is just edit index.php file.
lódfdsafds
ewrewrew
Its not working 🙁
yuytuytuyt tyretre re erterter ert ẻ432423432 32423423423423 423 423423
432423432432423
3432432
432423432
ewqewq
ewqewq rêwrew
ewqewqe
qưeerew
rưerewrew
rưerew
hi, nice tutorials. if it is possible write a tutorial on send MSG to phone. Thanks by the way good job!
amazing sir jee. i tried all others script but your script is working absoulutly amazing withour getting any error. thanx
Can you please share your files at [email protected], mine are not working
anyone can provide editing file of index.php file……because my code i notn working………my email id is [email protected]…(without username and password)
Hello sir I wan to know tht it may possibile to receive emails from smtp which email like [email protected] that is created from domain ?
i have download the code but it gives following error :
SMTP Error: Could not authenticate.1
how could i solve it
is there any changes needed is “php.ini” file
What SMTP server you are using and please make sure that you are giving correct login credentials.
If using gmail smtp try to use application password: https://support.google.com/mail/answer/1173270?hl=en
I am using same code but getting error like : SMTP Error: Could not connect to SMTP host. 1
that means your host is not valid post your host below.
i am getting the this error
SMTP Error: Could not authenticate.
1
i am using windows server where windows 2012 is installed. What will be the solution to get rid of this problem.
thanks
Invalid login details you are sending please check your login details.
Its not working ,Please update a new one
Warning: require_once(PHPMailer_v5.1/class.phpmailer.php): failed to open stream: No such file or directory in /home/appr7643/public_html/app/ma/index.php on line 2
Fatal error: Class ‘SMTP’ not found in /home/aaaa/public_html/app/ma/PHPMailer-master/class.phpmailer.php on line 1466