Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SMTP Authentication & mail() - Help Required

    Being able to send emails through PHP is a fundamental part of the site, so I've been searching around and trying to come up with some code to authenticate with the SMTP server to send the email. What I have at the moment is code found on the Internet to perform this task using the PEAR module. I assume this module is installed as the php.ini 'include_path' setting is c:\php4\pear. Please correct me if I am wrong:

    Code:
    require_once "Mail.php";
    
    $from = "MySite Mailer <admin@mysite.com>";
    $to = 'mailto@mailto.com';
    
    $host = "smtp.mysite.com";
    $username = "smtp_user";
    $password = "smtp_pass";
    
    $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);
    $smtp = Mail::factory('smtp',
      array ('host' => $host,
      'auth' => true,
      'username' => $username,
      'password' => $password));
    
    $mail = $smtp->send($to, $headers, $body);
    
    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
    } else {
      echo("Success!");
    }
    The error I am getting is as follows:

    Fatal error: sendmail(): Failed opening required 'Mail.php' (include_path='.;c:\php4\pear')

    I do not have a file called Mail.php in my directory listing, but I assumed this would be included by default through PEAR? I have not used PEAR before, so am unsure.

    Any help would be much appreciated.

    -Will

  • #2
    New Coder
    Join Date
    Sep 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There should be a file in the PHP directory called go-pear.bat, just click on it, then follow the directions.

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    The pear setting in the include path is there by default. It does not mean that the pear framework or any specific pear class is installed.

    A lot of servers don't have pear installed, so to create a stand a lone script that will work independent of what is present on the server, I recommend that you use the phpmailer class to do SMTP authentication - http://phpmailer.sourceforge.net/
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the quick reply. I have downloaded phpmailer and attempted to implement it. Although it is not returning an error, I am not receiving the email. Here is the code I am using (as part of a function):

    Code:
    	require('includes/class.phpmailer.php');
    	require('includes/class.smtp.php');
    
    	$mail = new PHPMailer();
    	$mail->SetLanguage('en', 'language');
    
    	$mail->IsSMTP();     // set mailer to use SMTP
    	$mail->Host = "smtp.mysite.com";  // specify main and backup server
    	$mail->SMTPAuth = true;     // turn on SMTP authentication
    	$mail->Username = "username";  // SMTP username
    	$mail->Password = "password"; // SMTP password
    	
    	$mail->From = "myemail@gmail.com";
    	$mail->FromName = "MySite.com Mailer";
    	$mail->AddAddress('mailto@address.com');
    	$mail->AddReplyTo("myemail@gmail.com", "MySite");
    	
    	$mail->IsHTML(true);                                  // set email format to HTML
    	
    	$mail->Subject = $subject;
    	$mail->Body    = $body;
    	$mail->AltBody = "";
    	
    	if(!$mail->Send())
    	{
    	   echo "Mailer Error: " . $mail->ErrorInfo;
    	   return 0;
    	} else { 
    		return 1;
    	}
    Does this code look correct? I've taken it from the PHPMailer documentation. If so, I'm guessing the problem lies elsewhere.

    Thanks again,

    -Will

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    are you doing this from your local computer ? and if so does your ISP block port 25 ? (mine (the biggest Australian ISP) does)
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi there and thanks for the reply.

    No, I'm executing the script from my webserver (hosting with Acecom). Since posting this thread up, I have actually received some test emails that have been sent - It just takes ~9 hours for them to arrive

    I can't understand why.

    -Will


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •