Hello All,
I had not been able to reliably send emails with the PHP mail function. So I decided I would use the PEAR extension instead, but I am having the same issue. I am not connecting to an SMTP server. The issue appears to be that I cannot send any email outside the domain. I don't receive any errors but the email never arrives. However it works for internal addresses. Being that I am on a hosted server, do I still need to modify the PHP.ini file? I don't believe so because it was loaded by default. Here is the code, I got it from an example on the PEAR site and it is similar to others I have found:
if(mysql_num_rows($result)>0){
$row = mysql_fetch_assoc($result);
$fname = $row['fname'];
$rmail = $row['email'];
$newpass = rangen();
$updte = "UPDATE members SET upass = '".md5($newpass)."' WHERE email = '".$rmail."'";
$res = mysql_query($updte);
if(!mysql_affected_rows() == 1){
$msg.= "Update failed:".mysql_error();
}
//Build the mail message
// Your name and email address
$sender = "Hey You <Me@mydomain.com>";
// The Recipients name and email address
$recipient = "Whats Up <You@yourdomain.com>";
// Subject for the email
$subject = "Your new Eternal Hour password";
// Text version of the email
$text = '
Hello '.ucfirst($fname).',
Here is your temporary password: '.$newpass.'.
Please change it from the preferences page after you log in.
Thank you,
Support
';
// HTML version of the email
$html = '
<html>
<body>
<ul style="margin: 0px; padding: 0px;">Hello <span style="color: blue; font-weight: bold;">'.ucfirst($fname).'</span>,</ul>
<li> </li>
<li>Here is your temporary password: <span style="font-weight: bold;">'.$newpass.'</span></li>
<li>Please change it from the preferences page after you log in.</li>
<li> </li>
<li>Thank you,</li>
<li style="color: blue; font-weight: bold;">Support</li>
</body>
</html>';
$crlf = "\n";
$headers = array(
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
// Sending the email
$mail = Mail::factory('mail');
$mail->send($recipient, $headers, $body);
if (PEAR::isError($mail)) {
$msg = $mail->getMessage() ;
}
else{
$msg.= "Your password has been sent, please check your inbox.";
}
}
I have researched and researched this. If anyone is familiar with this package I would really appreciate some advice.
EDIT: This is obviously a snippet of code. I also have these includes as well:
include_once('Mail.php');
include_once('Mail/mime.php');