Email activation smtp authentication

Hi ,
I have this script through which I would like to send an automatic email to clients upon registration, but the email is never sent. I am using my hostmonster’s Outgoing Mail Server:
However when I go into hostmonster and check email settings it says: Outgoing Mail Server: (server requires authentication) port 26.

Can anyone let me know what I can do to authenticate my outgoing mail server?

PHP script:

include ('connection.php');


$username = strtolower(strip_tags($_POST['username']));
$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);
$firstname = $_POST['inputfirstname'];
$lastname = $_POST['inputlastname'];
$desc = $_POST['inputdesc']; 
$email = $_POST['inputemail']; 
$email_confirm = $_POST['inputemail_confirmation'];
$phone = $_POST['inputphone']; 
$skype = $_POST['inputskype']; 
$house = $_POST['inputhousenumber']; 
$street = $_POST['inputstreet']; 
$city = $_POST['inputcity']; 
$state = $_POST['inputstate']; 
$country = $_POST['inputcountry']; 
$status = $_POST['inputstatus']; 
$period = $_POST['inputperiod']; 
$field = $_POST['inputfield'];
$language = $_POST['inputlanguage'];

$errorstring = "";

//default value of error string 
if (!$firstname ||(0 === preg_match("/\\S+/", $_POST['inputfirstname']))) $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Name<br></span>"; 
if (!$lastname ||(0 === preg_match("/\\S+/", $_POST['inputlastname']))) $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Lastname<br></span>"; 
if (!$email) $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Email<br></span>"; 
if ($status == "emergency"&& !$phone) $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Phone number is required for emergency assistance <br></span>";
if (preg_match('/[a-z]+/i', $_POST['inputphone'])) $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Phone number cannot contain letters<br></span>";
if (!$desc) $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Description<br></span>";
if ($country=="---" || $country=="Africa" || $country=="Europe" || $country=="Central-America" || $country=="North-America" || $country=="South-America" || $country=="Asia" || $country=="Middle-East")
    $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Country<br></span>";
if (!$language ||(0 === preg_match("/\\S+/", $_POST['inputlanguage'])))
    $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Languages spoken<br></span>";
if ($field=="---") $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Field of interest<br></span>";
if ($status=="---") $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Urgency of assistance<br></span>"; 
if ($period=="---") $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Period of time your information will stay posted<br></span>"; 
if (0 !==strcmp($_POST['inputemail'], $_POST['inputemail_confirmation'])) $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Emails do not match.</span>"; 

$namecheck = mysql_query("SELECT username FROM mainweb WHERE username='$username'");
  $count = mysql_num_rows($namecheck);

if (!$count==0)
      $errorstring = $errorstring."<span style='color: rgb(204, 0, 0);'>Username already taken!<br></span>";

    if ($password==$repeatpassword)
    if (strlen($username)>25)
                             {echo "Length of username is too long";}
       else {
      if (strlen($password)>25||strlen($password)<6)
                   echo "password must be between 6 and 25 characters";
                          //register the user 

                                //open database
                                   if ($errorstring!="")
echo "<u>Please fill out the following fields</u>:<br><br>$errorstring";

else { $password = md5($password);
                   $repeatpassword = md5($repeatpassword);
                   //generate random number for activation process
                     $random = rand(23456789,98765432);

  mysql_query ("INSERT INTO mainweb (`id`,`date`,`firstname`,`lastname`,`description`,`email`,`phonenumber`,`skype`,`house`,`street`,`city`,`state`,`country`,`soa`,`periodoftime`,`field`,`languages`,`username`,`password`,`random`,`activated`)
                   VALUES(NULL,NOW(),'$firstname','$lastname','$desc','$email','$phone','$skype','$house','$street','$city','$state','$country','$status','$period','$field','$language','$username','$password','$random','0')") or die(mysql_error());

                 [COLOR="Red"] $lastid = mysql_insert_id();

                   //send activation email
                   $to = $email;
                   $subject = "Activate your account";
                   $headers = "From:";
                   $server = "";


                   Hello $firstname,\

                   You need to activate your account with the link below:/n/n
                   //function to send email
                   mail($to, $subject, $body, $headers);

                   echo"<meta http-equiv='refresh' content='0;URL=' />"; 



        echo "Your passwords do not match";

      echo "Please fill out all necessary fields!";


PHP mail() command does not support authentication.

Use the PEAR mail package

Ya, I tried pear to authenticate smtp but it didn’t work.

I must be doing something wrong.

Which of the pear files do I have to upload to my websites’s server before testing my php code? I tried uploading pear.php and mail.php.

You need to include mail.php in your script too.

Heres a good tut.

Easier mail sending with PEAR::Mail | Practical PHP Programming | TuxRadar Linux

Check out Swift Mailer too, it’s worth a look and standalone. :slight_smile:

I tried the easier mail sending link you gave me.
I uploaded mail.php to my website’s server
and ran the following code: but it gave me this error: Call to undefined method PEAR_Error::send() in /home2/ciudada2/public_html/example.php on line 7


    $mail = Mail::factory("mail");

    $headers = array("From"=>"", "Subject"=>"Test Mail");
    $body = "This is a test!";
    $mail->send("", $headers, $body);

why do I keep on getting that error?
do I need to upload any other files to my website’s server"

the swift mailer you proposed doesn’t seem to have smtp authentication capabilities. At least not in their guide, and I wouldn’t know how to do it on my own.

thanks any way.

Yes, it does. It’s even on the front page of the site in big black letters. :stuck_out_tongue:

Here’s a link to the documentation. :wink:

Ok, thankx I got your link.

I’ll try it out.

After having downloaded the swift mailer, I tried to send an email to my own private email, but it wouldn’t work. I could only get it to send email to my web site hots’s email account (

Do you have any idea why?

this is the code I used:


require_once 'lib/swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('', 26)

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('' => 'Adam schroeder'))
  ->setTo(array('', '' => 'Ben'))
  ->setBcc(array('', '' => 'Adam'))
  ->setBody('This is what I said yesterday')

//Send the message
$result = $mailer->send($message);


//in your pear_mail_script.php do the following.

$paramsSMTP = array(
		"host" =&gt; "",
		"auth" =&gt; true,
		"username" =&gt; "",
		"password" =&gt; "somepassword"

	$mail = Mail::factory("smtp", $paramsSMTP);


// in your registration form include this.
//…all your other stuff here and then the following.
$user_ip = $_SERVER[‘REMOTE_ADDR’];

// stores sha1 of password
$sha1pass = PwdHash($data[‘pwd’]);

// Automatically collects the hostname or domain like
$host = $_SERVER[‘HTTP_HOST’];
$host_upper = strtoupper($host);
$path = rtrim(dirname($_SERVER[‘PHP_SELF’]), ‘/\\’);

// Generates activation code simple 4 digit number
$activ_code = rand(1000,9999);

$usr_email = $data[‘usr_email’];
$usr_email = strtolower($usr_email);
$user_name = $data[‘user_name’];
$user_name = ucwords(strtolower($user_name));

$sql_insert = "INSERT into users
mysql_query($sql_insert,$link) or die(“Insertion Failed:” . mysql_error());
$user_id = mysql_insert_id($link);
$md5_id = md5($user_id);
mysql_query(“update users set md5_id=‘$md5_id’ where id=‘$user_id’”);
// echo “<h3>Thank You</h3> We received your submission.”;

if($user_registration) {
$a_link = "

} else {
$a_link =
"Your account is PENDING APPROVAL and will be soon activated the administrator.

$message =
"Hello \

Thank you for registering with us. Here are your login details…\

We require that you validate your password to ensure that you instigated this action. \

This protects against unwanted spam and malicious abuse. Simply click on the link below. \

User ID: $user_name
Email: $usr_email \

Passwd: $data[pwd] \


Thank You




$recipient = $_POST['usr_email'];
$headers['From']    = "";
$headers['To']      = $_POST['user_name'];
$headers['Subject'] = 'Login Details';
$body = $message;

$mail-&gt;send($recipient, $headers, $body);

header(“Location: thankyou.php”);



i hope this helps.

Adam, I’m trying to do the same thing you are. Did you ever get your initial problem worked out?