0

i'm trying to create a code to send a email when a button is cliked, i fallowed this http://php.net/manual/en/function.mail.php to create the code and configured xamp by changing the code of php.ini, but it says that it cant connect to server:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP=smtp.gmail.com
; http://php.net/smtp-port
smtp_port=587

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = jun.atomo@gmail.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path sendmail_path ="\"C:\xampp\sendmail\sendmail.exe\" -t"

and senmail.ini:

smtp_server=smtp.gmail.com
smtp_port=587
auth_username=myemail@gmail.com
 auth_password=myppass

i used this form to call the php script:

 <form  action="/prototype/views/email-script.php" method="post">
     <p><input type="button"  name="orcrequest" id="orcrequest" value="Enviar Orçamento" class="btn btn-default">
     </form>

and this is the script:

<?php

if(isset($_POST['orcrequest']))
{

$to      = 'jun_otomo@hotmail.com'; //can receive notification

$subject = 'the subject';
$message = 'hello';
$headers = 'From: jun.atomo@gmail.com' . "\r\n" .
    'Reply-To: jun.atomo@gmail.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

echo 'Email Sent.';
}

?>
cthulhu
  • 169
  • 14
  • 1
    see here https://stackoverflow.com/questions/19132171/send-email-from-localhost-running-xammp-in-php-using-gmail-mail-server?rq=1 – Nikos Gkogkopoulos Feb 20 '18 at 15:17
  • @kerbholz i tried with submit and button, same result. – cthulhu Feb 20 '18 at 15:32
  • @NikosGkogkopoulos thanks , it stopped giving error but i still didnt received the e-mail. – cthulhu Feb 20 '18 at 16:25
  • a lot of the times, sendmail is improperly configured. If you could please try the same script on a live hosting server and get back to us with your results. I have had this kind of "error" before, but when the same script was used on a live server, the mail got sent just fine – Nikos Gkogkopoulos Feb 21 '18 at 07:18
  • Make sure you edited the correct `php.ini` (not the CLI one). Write a simple little script that just sends an email, no POST or stuff and see if that works. Check your junk/spam folder. If that doesn't work you might want to consider to use PHPMailer/Swiftmailer – brombeer Feb 21 '18 at 07:50

0 Answers0