SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast adamschroeder's Avatar
    Join Date
    Mar 2011
    Location
    World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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: mail.ciudadanossinfronteras.com.
    However when I go into hostmonster and check email settings it says: Outgoing Mail Server: mail.ciudadanossinfronteras.com (server requires authentication) port 26.

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


    PHP script:
    PHP Code:
    <?php 
    include ('connection.php');
    if(
    $submit)


    {
      

    $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 ||(=== preg_match("/\S+/"$_POST['inputfirstname']))) $errorstring $errorstring."<span style='color: rgb(204, 0, 0);'>Name<br></span>"
    if (!
    $lastname ||(=== 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 ||(=== 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 (
    !==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(
    $username&&$password&&$repeatpassword)
      {
        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";
                     }
                            else
                            {
                              
    //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: adamschroder@asia.com";
                       
    $server "mail.ciudadanossinfronteras.com";

                       
    ini_set("SMTP",$server);

                       
    $body="
                       Hello 
    $firstname,\n\n
                       You need to activate your account with the link below:/n/n
                       
                       http://ciudadanossinfronteras.com/activate.php?id=
    $lastid&code=$random
                       "
    ;
                      [/
    COLOR]
                       
    //function to send email
                       
    mail($to$subject$body$headers);

                       echo
    "<meta http-equiv='refresh' content='0;URL=http://ciudadanossinfronteras.com/thankyouhost.html' />"
         }

                            }

                }

        }
        else
            echo 
    "Your passwords do not match";

           }
      else
          echo 
    "Please fill out all necessary fields!";

    }
    ?>
    Last edited by SpacePhoenix; Mar 13, 2011 at 20:05. Reason: put php tags round php code to improve readability

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP mail() command does not support authentication.

    Use the PEAR mail package
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Enthusiast adamschroeder's Avatar
    Join Date
    Mar 2011
    Location
    World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  5. #5
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Check out Swift Mailer too, it's worth a look and standalone.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  6. #6
    SitePoint Enthusiast adamschroeder's Avatar
    Join Date
    Mar 2011
    Location
    World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    code:
    HTML Code:
    <?php
        include('Mail.php');
        $mail = Mail::factory("mail");
    
        $headers = array("From"=>"adam@asia.com", "Subject"=>"Test Mail");
        $body = "This is a test!";
        $mail->send("adamschroeder@asia.com", $headers, $body);
    ?>
    why do I keep on getting that error?
    do I need to upload any other files to my website's server"

  7. #7
    SitePoint Enthusiast adamschroeder's Avatar
    Join Date
    Mar 2011
    Location
    World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anthony,
    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.

  8. #8
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Yes, it does. It's even on the front page of the site in big black letters.

    Here's a link to the documentation.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  9. #9
    SitePoint Enthusiast adamschroeder's Avatar
    Join Date
    Mar 2011
    Location
    World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, thankx I got your link.

    I'll try it out.

  10. #10
    SitePoint Enthusiast adamschroeder's Avatar
    Join Date
    Mar 2011
    Location
    World
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 (admin@ciudanossinfronteras.com).

    Do you have any idea why?

    this is the code I used:
    HTML Code:
    <?php
    
    require_once 'lib/swift_required.php';
    
    //Create the Transport
    $transport = Swift_SmtpTransport::newInstance('mail.ciudanossinfronteras.com', 26)
      ->setUsername('admin@ciudadanossinfronteras.com')
      ->setPassword('******')
      ;
    
    //Create the Mailer using your created Transport
    $mailer = Swift_Mailer::newInstance($transport);
    
    //Create a message
    $message = Swift_Message::newInstance('Wonderful Subject')
      ->setFrom(array('duke2kill@hotmail.com' => 'Adam schroeder'))
      ->setTo(array('admin@ciudanossinfronteras.com', 'other@domain.org' => 'Ben'))
      ->setBcc(array('adamschroeder@mail.com', 'person2@otherdomain.org' => 'Adam'))
      ->setBody('This is what I said yesterday')
      ;
      
    
    
    //Send the message
    $result = $mailer->send($message);
    
    ?>

  11. #11
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    //in your pear_mail_script.php do the following.
    <?PHP
    require_once("Mail.php");

    $paramsSMTP = array(
    "host" => "smtp.yourhost.co.za",
    "auth" => true,
    "username" => "youremailwithhost.co.za",
    "password" => "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 example.com)
    $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`
    (`full_name`,`user_email`,`pwd`,`activation_code`,`user_name`
    )
    VALUES
    ('$data[full_name]','$usr_email','$sha1pass','$activ_code','$user_name'
    )
    ";
    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 = "
    *****ACTIVATION LINK*****\n
    http://$host$path/activate.php?user=$md5_id&activ_code=$activ_code
    ";
    } else {
    $a_link =
    "Your account is *PENDING APPROVAL* and will be soon activated the administrator.
    ";
    }

    $message =
    "Hello \n
    Thank you for registering with us. Here are your login details...\n
    We require that you validate your password to ensure that you instigated this action. \n
    This protects against unwanted spam and malicious abuse. Simply click on the link below. \n

    User ID: $user_name
    Email: $usr_email \n
    Passwd: $data[pwd] \n


    $a_link

    Thank You

    Administrator
    $host_upper
    ______________________________________________________
    THIS IS AN AUTOMATED RESPONSE.
    ***DO NOT RESPOND TO THIS EMAIL****
    ";

    require_once("pear_mail_script.php");

    $recipient = $_POST['usr_email'];
    $headers['From'] = "no-reply@someemail.co.za";
    $headers['To'] = $_POST['user_name'];
    $headers['Subject'] = 'Login Details';
    $body = $message;

    $mail->send($recipient, $headers, $body);


    header("Location: thankyou.php");
    exit();

    }
    }


    ?>
    i hope this helps.

  12. #12
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Adam, I'm trying to do the same thing you are. Did you ever get your initial problem worked out?

    Thanks!
    Convert your dollars into silver coins. www.convert2silver.com


Bookmarks

Posting Permissions

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