Page 1 of 1

PHP Mail - serious problem

Posted: Sat Aug 09, 2008 11:02 am
by jaandrws
I've got a serious problem trying to use the mail() function. The new VPS server I'm using requires authentication. This nullifies the mail() function's usefulness, I'm told. The company tells me that they cannot disable the authentication requirement for my account, and suggested the following solution, found at http://email.about.com/od/emailprogramm ... 073006.htm:

Code: Select all

 
<?php
require_once "Mail.php";
 
$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
 
$host = "ssl://mail.example.com";
$port = "465";
$username = "smtp_username";
$password = "smtp_password";
 
$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));
 
$mail = $smtp->send($to, $headers, $body);
 
if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>
 
I'm really having a hard time understanding this script and making it work. Frankly, I'd rather just disable authentication, but that is apparently not an option. SO, HERE'S WHERE I'M AT: The solution script they suggested begins with a require_once"Mail.php" command, BUT WHAT IS THIS FILE? Where do they say what's in it? How can I require a file that I don't have. As usual, I'm sure the solution is easy for others to understand, but my limited experience with this makes it VERY VERY difficult. I NEED HELP PLEEEEEEASE!

Re: PHP Mail - serious problem

Posted: Sat Aug 09, 2008 3:43 pm
by jbruni
I strongly suggest you to download and use htmlMimeMail:

Download here:
http://www.inthismachine.net/main/wp-co ... email5.zip

And example / instructions here:
http://www.inthismachine.net/main/archi ... ts-classes

The developer's site, with detailed documentation, is off line at the moment...
http://www.phpguru.org/

You will need to set up authentication using the setSMTPParams method:

Code: Select all

 
$mail->setSMTPParams($host, $port, null, true, $user, $pass);
 
$host, $port (normally is 25), $user and $pass values you should already know, or ask them o your VPS support

Hope that helps! Good luck!