The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Email php code fail!

Discussion in 'E-mail Discussions' started by fauvent, Dec 15, 2011.

  1. fauvent

    fauvent Registered

    Joined:
    Dec 15, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Guys, i know this may be very common and old thread, but I didnt find or maybe i didnt understand, old thread which have the exact situation than me. So please bear with me, since im not an professional coder.

    The thing is i have a server with multiple users, in spry.com, they use CPANEL to manage the server. I have been sending emails through a PHP web form for years, lets say 3 years to be more exact. But suddenly, they stop working gradually: first one, then twelve and today no a single one is working. I dont know what I am doing wrong here...

    As a coder (beginner) I have been told that i should specify better the mail stamp server or so. Maybe the server is blocking the php action because i dont have set all the code well.

    Im gong to let myself paste you guys the code here, I dont know if this will be helpful anyway. I will appreciate very very much your help because I have been going through a lot of problems with the customers because of this situation.

    Of course I have to add that i tried to solve this with the spry.com guys but they take very long and they dont look that they really want to help me in this one, and the spry blog is down!

    Here's the code:

    PHP:
    $contact_form = include "contacto.php";


    $destination="mymail@mail.com";
    $head"From: ".strip_tags($_POST['email']);
    $name=strip_tags($_POST['name']);
    $telefono=strip_tags($_POST['telefono']);
    $email=strip_tags($_POST['email']);
    $mes=strip_tags($_POST['mes']);
    $subject="Mensage desde mydomain.co";
    $error="";
    $mes="Nombre: $name\n
    Telefono: 
    $country\n
    Comentario: 
    $mes\n";


    if (!
    preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i"$email)) {die ("<div style=\"position: absolute; left: 330px; top: 500px; font-size:16px\"><a href=javascript:window.history.back()>Haga click aqui <br /> Vuelva e introdusca un email valido</a></div>");}
    if (!
    preg_match("/^[0-9_]{1,}$/"$telefono)) {die ("<div style=\"position: absolute; left: 330px; top: 500px; font-size:16px\"><a href=javascript:window.history.back()>Haga click aqui <br /> Vuelva e introdusca un telefono valido</a></div>");}
    if (!
    preg_match("/^[A-Za-z0-9-_\",\'\s]+$/"$_POST["mes"])) {die ("<div style=\"position: absolute; left: 330px; top: 500px; font-size:16px\"><a href=javascript:window.history.back()>Haga click aqui <br /> Vuelva e introdusca un mensaje valido</a></div>");}
    if (!
    preg_match("/^[A-Za-z0-9-_'\s]+$/"$_POST["name"])) {die ("<div style=\"position: absolute; left: 330px; top: 500px; font-size:16px\"><a href=javascript:window.history.back()>Haga click aqui <br /> Vuelva e introdusca un nombre valido</a></div>");}


    if(
    $error==""){


    if(
    mail($destination,$subject,$mes,$head)){
    echo 
    "<html><head><meta http-equiv='refresh' content='1; url=http://www.mydomail.com/contacto.php?msg=Gracias por sus comentarios. En breve nos contactaremos con usted.'></head></html>";
    }


    }
    else{
    echo 
    "<a href=javascript:window.history.back()>Come back and fill all the fields up.</a><br>";
    exit;
    }


    $to $_POST['email']; 
    $msg "Gracias por sus comentarios. Nos contactaremos con usted en breve.\n\n My company Staff";
    //Image in e-mail
    $mailimg '
    <img src="http://www.mydomain.co/images/logo2.jpg">
    '
    ;
    //Mail Body - Position, background, font color, font size...
    $body ='
    <html>
    <head>
    <style>
    <!--
    body, P.msoNormal, LI.msoNormal
    {
    background-position: top;
    background-color: #FFFFFF;
    margin-left:  1em;
    margin-top: 1em;
    font-family: "arial";
    font-size:   10pt;
    font-weight:normal ;
    color:    "000000";
    }
    -->
    </style>
    </head>
    </body> 
    '
    ;
    //To send HTML mail, the Content-type header must be set:
    $headers='MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html;charset=iso-8859-1' "\r\n";
    $headers .= 'From: Info <x@mydomain.co>' "\r\n";
    $bodys .= "$msg <br>";
    $bodys .= "$mailimg";
    $subject .="Gracias por sus comentarios";




    $body $body $bodys;
    mail($to$subject$body$headers);

    I appreciate your time.
    Thank you
     
  2. alphawolf50

    alphawolf50 Well-Known Member

    Joined:
    Apr 28, 2011
    Messages:
    186
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    You should use something like PHPMailer to authenticate with your SMTP server. The code you provided does not authenticate to an SMTP server at all.
     
Loading...

Share This Page