where is issue with SMTP authentication ?

Discussion in 'Email' started by zali, Feb 28, 2015.

  1. Hello, I am very new to PHP, i creating a website and got hosting here on Winhost. i have send email form which normally works but at this hosting it is not working. I understand SMTP is not working on this host and i saw that link too https://support.Winhost.com/kb/a826/how-to-send-email-from-a-php-application.aspx but i am not understanding what changes i should in my code for it to work.

    Please see the below code and help me in getting the required change it.

    FILE 1, register.php (this is form)
    <form name="contactform" method="post" action="send_form_email.php">
    <table width="360">
    <tr class="style4">
    <td width="166" valign="top" class="style4">
    <label for="first_name">First Name *</label> </td>
    <td width="182" valign="top">
    <input type="text" name="first_name" maxlength="50" size="30">
    </td>
    </tr>
    <tr class="style4">
    <td valign="top" class="style4"">
    <label for="last_name">Last Name *</label> </td>
    <td valign="top">
    <input type="text" name="last_name" maxlength="50" size="30">
    </td>
    </tr>
    <tr class="style4">
    <td valign="top" class="style4">
    <label for="email">Email Address *</label> </td>
    <td valign="top">
    <input type="text" name="email" maxlength="80" size="30">
    </td>
    </tr>
    <tr class="style4">
    <td valign="top" class="style4">
    <label for="telephone">Telephone Number</label> </td>
    <td valign="top">
    <input type="text" name="telephone" maxlength="30" size="30">
    </td>
    </tr>
    <tr class="style4">
    <td valign="top" class="style4">Address</td>
    <td valign="top"><textarea name="address" cols="23" rows="6" id="address"></textarea></td>
    </tr>
    <tr class="style4">
    <td valign="top" class="style4">Gender</td>
    <td valign="top"><select name="gender" id="gender">
    <option value="male">Male</option>
    <option value="female">Female</option>
    </select></td>
    </tr>
    <tr class="style4">
    <td valign="top" class="style4">Date of Birth </td>
    <td valign="top"><p>
    <input name="dob" type="text" id="dob" size="30" maxlength="30">
    <br>
    e.g. 22/2/1998</p></td>
    </tr>
    <tr class="style4">
    <td valign="top" class="style4">Course</td>
    <td valign="top"><select name="course" id="course">
    <option value="Mental Calculator">Mental Calculator</option>
    <option value="Human Callender">Human Callender</option>
    <option value="Photographic Memory">Photographic Memory</option>
    </select></td>
    </tr>
    <tr class="style4">
    <td valign="top" class="style4">
    <label for="comments">Comments </label></td>
    <td valign="top">
    <textarea name="comments" cols="23" rows="6"></textarea>
    </td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:center">
    <div align="right">
    <input name="submit" type="submit" value="Submit">
    </div></td>
    </tr>
    </table>
    </form></td>
    </tr>
    </table>


    FILE 2, send_form_email.php

    <?php
    if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "[email protected]";
    $email_subject = "Email for MAPD";


    function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";

    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
    !isset($_POST['last_name']) ||
    !isset($_POST['email']) ||
    !isset($_POST['telephone']) ||
    !isset($_POST['address']) ||
    !isset($_POST['gender']) ||
    !isset($_POST['dob']) ||
    !isset($_POST['course']) ||
    !isset($_POST['comments'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $address = $_POST['address']; // not required
    $gender = $_POST['gender']; // not required
    $dob = $_POST['dob']; // not required
    $course = $_POST['course']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
    }
    $string_exp = "/^[A-Za-z .'-]+$/";
    if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
    }
    if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
    }
    // if(strlen($comments) < 2) {
    // $error_message .= 'The Comments you entered do not appear to be valid.<br />';
    // }
    if(strlen($error_message) > 0) {
    died($error_message);
    }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Address: ".clean_string($address)."\n";
    $email_message .= "Gender: ".clean_string($gender)."\n";
    $email_message .= "Date of Birth: ".clean_string($dob)."\n";
    $email_message .= "Course: ".clean_string($course)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";


    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    ?>
    <!-- include your own success html here -->
    <p><span class="style1">Thank you so much for your comments</span></p>
    <p class="style17 style1 style5">Best Regards,</p>
    <p><span class="style17 style1 style5">MAPD</span>
    <?php
    }
    ?>
     
    Last edited by a moderator: Oct 14, 2015
  2. please check below code and tell where is the mistake? i don't receive a test email.
    should i upload Mail.php file in my hosting folder? if yes from where i can get it? or is there any other error?

    <?php
    require_once "Mail.php";
    $from = "Sender <[email protected]>";
    $to = "Recipient <[email protected]>";
    $subject = "This is a test email sent via php";
    $body = "This is a test email";
    $host = "mail.mapd.co";
    $username = "[email protected]";
    $password = "xxxxxxxx";
    $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);
    ?>
     
  3. ComputerMan

    ComputerMan Winhost Staff

    Try changing the PHP version to 5.3 and then recycle the application pool. After that allow two minutes to pass and try your php script.
     
    Michael likes this.

Share This Page