Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

How to use smtp function in php with authentication

Discussion in 'E-mail Discussion' started by Webnook, Jan 31, 2018.

  1. Webnook

    Webnook Registered

    Joined:
    Jan 31, 2018
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    India
    cPanel Access Level:
    Website Owner
    My code is as given below. I would like to know how to use smtp function in php with authentication in contact form. If I use hotmail id I am not able to recive the inquiry but it works fine for gmail id. It would be great if someone help in me editing my code noted below

    <?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $message = $_POST['message'];
    $formcontent=" Name: $name \n Email: $email \n Phone: $phone \n Message: $message";
    $to = "abc@hotmail.com";
    $subject = "Contact Form";
    $mailheader = "From: $name \r\n";
    mail($to, $subject, $formcontent, $mailheader) or die("Error!");
    echo "<br><br><p style='color:#000'><b>Thank You $name</b></p><p style='color:#000'>We will be in touch as soon as possible.</p>";
    echo "<p style='color:#000'>Go to <a href='index.html'><b>Home Page</b></a></p>";
    ?>
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,344
    Likes Received:
    1,852
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    It's likely the issue is that Hotmail isn't accepting the message because the form you referenced doesn't use SMTP authentication (it looks to use the PHP mail function). Your web hosting provider could review the Exim logs to confirm if that's the case. We don't offer help with coding, but you may want to check with a website such as StackOverflow for help developing a PHP form that uses SMTP authentication. EX:

    Need SMTP authentication in my PHP form?

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. rpvw

    rpvw Well-Known Member

    Joined:
    Jul 18, 2013
    Messages:
    722
    Likes Received:
    245
    Trophy Points:
    93
    Location:
    Spain
    cPanel Access Level:
    Root Administrator
    By far the best way to fix this is what cPanelMichael instructed you to do in the previous post.

    If you want to try something that is a lot easier (but is not guaranteed to work with Hotmail - you will have to experiment)

    Add the fifth parameter to your mail() line something like
    PHP:
    mail($to$subject$formcontent$mailheader"-f you@yourdomain.com") or die("Error!");
    or you could try
    PHP:
    mail($to$subject$formcontent$mailheader"-f" .$email) or die("Error!");
    I think you will get the best results by using a -f parameter that matches the same domain on the server that is executing the mail() function.

    See the PHP manual for full details PHP: mail - Manual
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    cPanelMichael likes this.
  4. Webnook

    Webnook Registered

    Joined:
    Jan 31, 2018
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    India
    cPanel Access Level:
    Website Owner



    Thanks a lot.. :):) It worked for me.. But Why the mail is receiving in "Other" folder. It should be displayed under "Focused" right. Please tel me, If you have any idea about this.
     
  5. Webnook

    Webnook Registered

    Joined:
    Jan 31, 2018
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    India
    cPanel Access Level:
    Website Owner
    One more query regarding Contact form :

    When I receive the contact form inquiries on my mail id, It shows as removed and I can't directly reply to the sender. See the attached screenshot.

    Can anyone help me out through which I can avoid the above situation and get the sender email id in place of removed so that I can directly reply.

    ** I had changed $mailheader = "From: $name \r\n"; to "From: $email \r\n"; but then I can't receive inquiry from yahoo users. :(
     

    Attached Files:

    #5 Webnook, Feb 1, 2018
    Last edited by a moderator: Feb 1, 2018
  6. Webnook

    Webnook Registered

    Joined:
    Jan 31, 2018
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    India
    cPanel Access Level:
    Website Owner
    [QUOTE="Add the fifth parameter to your mail() line something like
    PHP:
    mail($to$subject$formcontent$mailheader"-f you@yourdomain.com") or die("Error!");
    or you could try
    PHP:
    mail($to$subject$formcontent$mailheader"-f" .$email) or die("Error!");
    I think you will get the best results by using a -f parameter that matches the same domain on the server that is executing the mail() function.
    [/QUOTE]

    But I am not able to receive inquiries from mobile, i
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,344
    Likes Received:
    1,852
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Generally, you're going to want to use SMTP authentication instead of the PHP mail function to avoid the problems you have reported. Note you will likely receive more user-feedback on how to create or modify the PHP coding on a website such as StackOverflow.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Zardiw

    Zardiw Active Member

    Joined:
    Sep 22, 2017
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Palm Springs
    cPanel Access Level:
    Root Administrator
    I would use PHPMailer instead of PHP mail function.

    sourceforge.net/projects/phpmailer/
     
    #8 Zardiw, Aug 4, 2018
    Last edited by a moderator: Aug 4, 2018
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice