-1

I'm trying to send emails with php in local, i have modified php.ini and sendmail.ini but still still doesnt work.

The IDE doesn't even give me Errors or a Warnings like Failed to connect to mailserver at "localhost" port 25 or something like that

php.ini


SMTP=smtp.gmail.com
smtp_port=465
sendmail_from = biagiosani2005@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

and sendmail.ini

smtp_server=smtp.gmail.com
smtp_port=465
error_logfile=error.log
debug_logfile=debug.log
auth_username=biagiosani2005@gmail.com
auth_password=xxxxxxxx
force_sender=biagiosani2005@gmail.com
<?php
        

$to = "luciasani2005@gmail.com";
$subject = "this is a subject";
$message = "this is a message";
mail($to, $subject, $message);


?>
  • 1
    Have you read through https://stackoverflow.com/a/24644450/231316? – Chris Haas Nov 06 '22 at 12:34
  • 2
    Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – Warren Sergent Nov 09 '22 at 01:43

1 Answers1

-3

It is not SMTP send mail. You have SMTP configurations, it is okay, but your sending way is wrong. You need to use PHPMailer package and to correct script such:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require './PHPMailer-master/src/Exception.php';
require './PHPMailer-master/src/PHPMailer.php';
require './PHPMailer-master/src/SMTP.php';
$html = "<h1>Hello </h1>";
$mail = new PHPMailer(true);
try {
    //Server settings
    $mail->isSMTP();                                          
    $mail->Host       = 'smtp.titan.email'; 
    $mail->SMTPAuth   = true;                                 
    $mail->Username   = 'contact@domain.com';               
    $mail->Password   = 'password';                           
    $mail->SMTPSecure = 'ssl';                                  
    $mail->Port       = 465;                                  

    //Recipients
    $mail->setFrom('contact@domain.com', 'domain Team');
    $mail->addAddress('receiver1@gmail.com', 'Joe User');    
    $mail->addAddress('receiver2@gmail.com', 'Joe User');    
    // Attachments
    // Content
    $mail->isHTML(true);                                 
    $mail->Subject = 'Here is the subject';
    $mail->Body    = $html;
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    $mail->send();
    echo true;

} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
Tural Rzaxanov
  • 783
  • 1
  • 7
  • 16