Web Analytics Made Easy -
StatCounter Contact us form - CodingForum

Announcement

Collapse
No announcement yet.

Contact us form

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Contact us form

    Dear friends

    I am newby in PHP, but I am sure this code I found on web it is right.

    I did 2 tests with an enail account from GMAIL and another account email from my SERVER. Not works!

    It gives the following message

    Warning: mail(): SMTP server response: 554 5.5.4 [email protected] is not an e-mail address hosted on this web server. Please contact technical support if you wish to bypass this check. in contactus.php on line 16

    Warning: mail(): SMTP server response: 554 5.5.4 [email protected] is not an e-mail address hosted on this web server. Please contact technical support if you wish to bypass this check. in contactus.php on line 17


    <php>
    <?php

    if(isset($_POST['submit'])){
    $to = "[email protected]"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
    ?>

    <!DOCTYPE html>
    <head>
    <title>Form submission</title>
    </head>
    <body>

    <form action="" method="post">
    First Name: <input type="text" name="first_name"><br>
    Last Name: <input type="text" name="last_name"><br>
    Email: <input type="text" name="email"><br>
    Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
    <input type="submit" name="submit" value="Submit">
    </form>

    </body>
    </html>
    </php>


    Could someone help me?

    Thanks

  • #2
    I did 2 tests with an enail account from GMAIL and another account email from my SERVER. Not works!
    afaik, gmail only works over SMTP, for which you would have to configure your sendmail executable for.

    generally, use a mailing library like SwiftMailer or PHPMailer. they're more reliable (and know how to properly set up an email) than mail().
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

    Comment


    • #3
      Originally posted by Dormilich View Post
      afaik, gmail only works over SMTP, for which you would have to configure your sendmail executable for.

      generally, use a mailing library like SwiftMailer or PHPMailer. they're more reliable (and know how to properly set up an email) than mail().
      Thank you.

      Now I am using an email account from a Server, but the error message it is the same.

      Comment


      • #4
        The problem is the "from" email address.

        Many webhosts now require the "from" address to be the same as your domain name, or your own email. The error message says you can contact them to bypass that rule, but since it's just a contact form, use your own email address as both the "to" AND "from".

        Because it's a contact form, you already know where it comes from ... it comes from your website, so you'll see the email coming in with your own email address as the "from".

        So make the "from" your own email address that is part of your domain (webhost account).

        Then, in the message part of the form you will put the person's email address ... the person that sent the form and entered their email address. Or, sneak the sender's email in the subject line, which you have already created yourself. Never let anyone else create or control the subject line from the contact form.

        See if that works.
        Last edited by mlseim; Sep 13, 2016, 04:54 PM.

        Comment


        • #5
          miseim,

          Thank you so much!

          It works very fine.

          Comment

          Working...
          X