-1

I have been trying to make this work using XAMPP and for some reason the mail function does not work, here is my code. I'm in a MAC and my php.ini in the etc folder and I don't have the sendmail folder.

$_POST['email'];

$result = mail('someEmail@gmail.com', 'This is a Subject', 'This is the body of the email', 'From: $email');
echo $result ? 'Sent' : 'Error';
ricosuave
  • 47
  • 6

2 Answers2

0

The email function will work correctly when you upload this code to a server, and sends email to the user.

try this code, that works perfectly when put into a file on the server:

<?php
$to = "xyz@somedomain.com";
$subject = "This is subject";
$message = "This is simple text message.";
$header = "From:abc@somedomain.com \r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true )  
{
  echo "Message sent successfully...";
}
else
{
  echo "Message could not be sent...";
}
?> 
0

You can`t directly from localhost. One way is to move your code to public server or using some SMTP server if you want to work on your localhost. You should make some changes to those two files xampp\php\php.ini and xampp\sendmail\sendmail.ini

in php.ini file search and find [mail function] and make it look like this

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

now in sendmail.ini make sure it look like this

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=465
error_logfile=error.log
debug_logfile=debug.log
auth_username=YOUR_MAIL@gmail.com
auth_password=YOUR_MAIL_PASS
force_sender=YOUR_MAIL@gmail.com

Now make sure in php.ini

extension=php_openssl.dll

is uncommented. Also make sure to comment following line if there is another sendmail_path

sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

If everything is OK your will be sending mail from localhost using google gmail. So the receiver will see your gmail in FROM field

Petko Kostov
  • 367
  • 1
  • 9