Skip to content
Advertisement

XAMPP send mail not working PHP

here are the details

[php.ini]

SMTP = smtp.gmail.com
smtp_port = 465
sendmail_path = ""C:xamppsendmailsendmail.exe" -t"
mail.add_x_header=Off

[sendmail.ini]

smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=ssl
error_logfile=error.log
debug_logfile=debug.log
auth_username=[email]@gmail.com
auth_password=[email password]
pop3_server=
pop3_username=
pop3_password=
force_sender=[email]@gmail.com
force_recipient=
hostname=smtp.gmail.com



 [mail function]
    mail('[email]@gmail.com','sample mail','sample content','From: anotheremail@gmail.com');

i have checked smtp settings properly, but its still not working please suggest.

Advertisement

Answer

You have to configure SMTP on your server

You can use the googles free SMTP server Pretty easy to setup too.

<?php

$mail = new PHPMailer(true);

//Send mail using gmail
if($send_using_gmail){
    $mail->IsSMTP(); // telling the class to use SMTP
    $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 = "your-gmail-account@gmail.com"; // GMAIL username
    $mail->Password = "your-gmail-password"; // GMAIL password
}

//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom($email_from, $name_from);
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";

try{
    $mail->Send();
    echo "Success!";
} catch(Exception $e){
    //Something went bad
    echo "Fail :(";
}

?>

You can try below as well.

You can send mail from localhost with sendmail package , sendmail package is inbuild in XAMPP. So if you are using XAMPP then you can easily send mail from localhost.

for example you can configure C:xamppphpphp.iniandc:xamppsendmailsendmail.ini for gmail to send mail.

in C:xamppphpphp.ini find extension=php_openssl.dll and remove the semicolon from the beginning of that line to make SSL working for gmail for localhost.

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

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = test@gmail.com
sendmail_path = ""C:xamppsendmailsendmail.exe" -t"
Now Open C:xamppsendmailsendmail.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=test@gmail.com
auth_password=my-gmail-password
force_sender=test@gmail.com

//mail function

$mail=test@test.com
mail($mail, 'Subject', 'sample mail', 'From: test@axxx.ba');
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement