1

I want to send mail from my php script, but unable to find the configuration settings for mac and gmail. My php script is:

   $to ="sender email id";
   $subject = "Confirmation";
   $header = "";
   $message = "";
   $sentmail = mail($to,$subject,$message,$header);

   if($sentmail)
   {
      echo "Your Confirmation link Has Been Sent To Your Email Address.<br>";
   }
   else
   {
      echo "Cannot send Confirmation link to your e-mail address<br>";
   }

I have also try another code on my ubuntu machine using Mail.php, but it shows some authentification error. Here's the code:

include_once "Mail-1.2.0/Mail-1.2.0/Mail.php";

$from = '<sender@gmail.com>';
$to = '<receiver@gmail.com>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";

$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => '465',
    'auth' => true,
    'username' => 'sender@gmail.com',
    'password' => 'xxxxx'
 ));



$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo('<p>' . $mail->getMessage() . '</p>');
} else {
 echo('<p>Message successfully sent!</p>');
}

Provide me some solution so that I can successfully mail from my php script.


Mukul Aggarwal
  • 1,515
  • 20
  • 16

1 Answers1

0

Try changing your header on your first script to this:

$header = 'From: put from email address here' . "\r\n" .
        'Reply-To: put from email address here' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
Nicholas Roberts
  • 222
  • 4
  • 13