email not sending from php

Discussion in 'Email' started by Ravi Swaminathan, May 29, 2014.

  1. Hello,
    I moved my site to Winhost recently and have to change my mail from php mail to smtp which is fine. But I am not able to send any mail from my php file. I am getting a success back and being redirected to the thank you page after the mail call. Any help would be greatly appreciated

    I use outlook as my mail so I have tried both mail.entroids.com and the host and smtp.live.com and getting the same results.

    Here is the code(changed the password ofcourse)
    <?php

    require_once "Mail.php";
    //require_once "Mail/mime.php";

    function send_email($to, $user_name, $subject, $template_name, $fname) {

    // common for all landing page emails
    $from = 'Entroids <contact@entroids.com>';
    $mail_to = $user_name . '<' . $to . '>';
    //$num = md5(time());
    $server_name = $_SERVER["SERVER_NAME"];
    //$file_name = "http://" . $server_name . '/downloads/' . $fname;
    $file_name = '/downloads/' . $fname;
    //$crlf = "\r\n";
    $host = "mail.entroids.com";
    $username = "admin@entriods.com";
    $pass = "mypassword";

    $html_message = "<html><body>";
    $html_message .= '<table width="900px">';
    $html_message .= '<tr style="background-color:#01aebc"><td><a href="http://www.entroids.com"><img src="http://' . $server_name . '/Images/logo.png" align="left"></a></td></tr>';
    $html_message .= "<tr><td><br/><span>Dear " . $user_name . ",</span></td></tr>";
    $html_message .= "<tr><td>Congratulations for making an effort to drive excellence in execution. </td></tr>";
    //$html_message .= '<tr><td>Please click this <a href="http://' . $server_name . '/downloads/' . $fname .'">link</a> to dowload the ' . $template_name .'.</td></tr>';
    $html_message .= '<tr><td>Please click this <a href="' . $file_name .'">link</a> to dowload the ' . $template_name .'.</td></tr>';
    $html_message .= "<tr><td>&nbsp;</td></tr>";
    $html_message .= "<tr><td>We love to hear your feedback. To contact us click ". '<a href="mailto: ' . $from_mail . '">here</a> or email contact@entroids.com.' ."</td></tr>";
    $html_message .= "<tr><td>&nbsp;</td></tr>";
    $html_message .= '<tr><td>We are soon launching a platform of startup management tools. Currently accepting limited number of beta users. Click <a href="http://www.entroids.com">here</a> to signup.</td></tr>';
    $html_message .= "<tr><td>&nbsp;</td></tr>";
    $html_message .= "<tr><td>Enjoy your startup journey! </td></tr>";
    $html_message .= "<tr><td>&nbsp;</td></tr>";
    $html_message .= '<tr><td><img src="http://' . $server_name . '/Images/chandra.png" alt="Chandra Gollapudi" style="width: 105px;"></td></tr>';
    $html_message .= "<tr><td>Chandra Gollapudi</td></tr>";
    $html_message .= "<tr><td>Co-founder/CMO</td></tr>";
    $html_message .= '<tr><td><a href="http://ca.linkedin.com/pub/chandra-gollapudi/14/20a/a29"><img src="http://' . $server_name . '/Images/linkedinbtn.png" width="80" height="15" border="0" alt="View Chandra Gollapudi profile on LinkedIn"></a></td></tr>';
    $html_message .= "<tr><td>&nbsp;</td></tr>";
    $html_message .= "<tr><td>P.S: Learn more on startup execution by visiting our ". '<a href="http://blog.entroids.com">blog</a>.' ."</td></tr>";
    $html_message .= "</table>";
    $html_message .= "</body></html>";
    $html_message = wordwrap($html_message, 100);

    $text_message = "Thanks for your interest in Entroids. Here is the template you requested. Thanks Entroids Team\r\n";

    $headers = array ('From' => $from, 'To' => $mail_to, 'Subject' => $subject);
    echo $html_message;
    $smtp = Mail::factory('smtp', array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $pass));
    //return ($smtp->send($mail_to, $headers, $html_message));
    $mail = $smtp->send($mail_to, $headers, $html_message);
    if ($mail)
    return $mail;
    else
    echo "Mail delivery unsuccessful!!!";
     
    Last edited by a moderator: Oct 14, 2015
  2. FredC

    FredC Winhost Staff

    It looks like your domain's MX is pointing to live.com and its hard for us to trace where the mail went.

    If you are not getting any error from the page, the mail is accepted by the mail server.
     
  3. Thanks for the reply, I was using php mail() function before with my old hosting server. I cannot use that with Winhost correct? I am not seeing any echo statement I put in this php either.
     
    Last edited by a moderator: Oct 14, 2015
  4. I was able to download phpmailer and I am using this code now and I am getting 2014-06-02 01:41:18 SMTP ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it. (10061) SMTP connect() failed. Mailer Error: SMTP connect() failed. as error.

    <?php

    require('class.phpmailer.php');

    function send_email($to, $user_name, $subject, $template_name, $fname) {

    $html_message = "<html><body>";
    $html_message .= '<table width="900px">';
    $html_message .= '<tr><td>Hello this is a test message</td></tr>';
    $html_message .= "</table>";
    $html_message .= "</body></html>";

    $mailObj = new PHPMailer();
    $mailObj->isSMTP();
    $mailObj->CharSet = 'UTF-8';
    $maiObj->Host = "smtp-mail.outlook.com";
    $mailObj->SMTPAuth = true; // Enable SMTP authentication
    //$mailObj->AuthType = 'PLAIN';
    $mailObj->Port = 587;
    $mailObj->Username = "contact@entroids.com"; // SMTP username
    $mailObj->Password = "Password"; // SMTP password
    $mailObj->SMTPSecure = "tls"; // Enable encryption, 'ssl' also accepted
    $mailObj->From = 'contact@entroids.com';
    $mailObj->FromName = 'Entroids';
    $mailObj->addAddress($to, $user_name);
    $mailObj->isHTML(true);
    $mailObj->WordWrap = 100;
    $mailObj->Subject = $subject;
    //$mailObj->Hostname = "entroids.com";
    $mailObj->SMTPDebug = 1;


    $mailObj->Body = $html_message;
    $mailObj->AltBody = "Thanks for your interest in Entroids. Here is the template you requested. Thanks Entroids Team\r\n";

    $mail = $mailObj->send();
    if ($mail)
    return $mail;
    else
    echo "Mailer Error: " . $mailObj->ErrorInfo;
    }
    ?>
     

Share This Page