-1

PHP newbie here. I am trying to send an email to the user when the user registration is successful.

I have done my part of the research on how to send email on PHP, and most of them suggests using mail(). But seems like it requires an SMTP server. So I have decided to use PHPmailer. I have looked at the example codes, but didn't understand how to use it. Can anyone give me an example and explain the code snippet?

First question here!

Proteeti Prova
  • 1,079
  • 4
  • 25
  • 49
  • 1
    Base your code on the examples provided with PHPMailer, and read the docs. If you still have trouble, come back here and search, and if you can't find an answer, post a question. – Synchro May 02 '17 at 05:27

1 Answers1

-2

If you added all your needed phpmailer scripts to your project folder (like PHPMailerAutoload.php, class.phpmailer.php, class.smtp.php) you can add to your php file the following code:

require('class.phpmailer.php');
require('class.smtp.php');

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.yourserver.de";     
$mail->Port = 465;  
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;     /
$mail->Username = "myusername@mail.com"; 
$mail->Password = "secure123";  
$mail->CharSet ="UTF-8";
$mail->AddAddress("m@il.to");
$mail->Subject = "Important Subject";   
$mail->IsHTML(true); //Or false if you do not want HTML content  
$mail->Body = "HTML-Body<br>Go for it: <b>Great</b> story goes here!";
$mail->AltBody = "No HTML Body. Great story goes here!";

if(!$mail->Send()){
echo "Error sending";
} else {
echo "Mail successfully sent";
}

If you want to send a mail, you have to run a smtp server. Do you run your server privately? Is there no way you can build a smtp server functionality?

Best Chris

cpro90
  • 176
  • 10
  • 1
    If you're going to post example code, at least use an up to date example that shows the right way to work. This old code is lining up for several issues. – Synchro May 02 '17 at 05:30