-1

I want to know how to send mail in php. I have tried the php mailer but it doesn't work. Can we send email from local host?

<?php
require_once 'class.phpmailer.php';
$mailer = new PHPMailer();
$mailer->CharSet = 'utf-8';
$mailer->AddAddress("gkpmanu@gmail@gmail.com");
$mailer->Subject = "Student Registration";
$mailer->From = "coursereg@gmail.com";
$mailer->FromName = "course registration system";
// $mailer->AddBCC("nitcoursereg@gmail.com", "Registeration");   
$mailer->Body ="You have registered";
if($mailer->Send()){
    echo "Sent";
}
else
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    echo "Not Sent";
?>
  • You need to be a bit more precise than "it doesn't work". What happens? What error is shown? What's in yor local mail server's log? – Synchro May 14 '15 at 15:32
  • possible duplicate of [Configure WAMP server to send email](http://stackoverflow.com/questions/5773288/configure-wamp-server-to-send-email) – anshabhi Jun 13 '15 at 17:33

2 Answers2

1

Your code is fine but as you are saying that you are on local host and i am assuming that you are not on a public ip address. To send a mail you can also use mail() function of php. You can configure the stmp details in php.ini file of your localhost, but you need to have a public mail server running on your localhost. Public mail server in the sense i mean to say a mail server running on your localhost with open ports for stmp(port:25), where your ip address is a public ip address.

I hope this helps you.

Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33
  • I don't advise anyone to call `mail()` directly, especially not a beginner. You are pretty much guaranteed to do it wrong in one way or another. – Synchro May 14 '15 at 15:30
  • @Synchro, it depends on the person who uses the mail function, i use this function most of the time and i am pretty comfortable with it, though sometimes i use phpmailer in some projects. – Sourabh Kumar Sharma May 14 '15 at 15:57
0

==================================================================== download phpMailer library from https://code.google.com/archive/a/apache-extras.org/p/phpmailer/downloads

and download PHPMailer_5.2.4.zip from that and paste below code in where you want to send mail

Devang Hire
  • 174
  • 1
  • 5