Email Problem using PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpmind
    New Member
    • Feb 2008
    • 16

    Email Problem using PHP

    I am attempting to send and email via my feedback form and nothing seems to go thru. I have tried sending to a yahoo account and a gmail account. I have changed a few things in my script several times and did receive a couple emails about 1 day later that just went into bulk. As of now I receive nothing. Can someone please take a look at my script and tell me what I am doing wrong. Also how do I prevent mails from going to bulk/spam? Could this be an issue with my web hosting company ?

    Form.php
    [php]
    <form method="post" action="sendfee dback.php">
    <div align="center">
    <p align="center"> <font face='Verdana' >Contact Us</font> </p>
    <p>Feedback<b r>
    <textarea name="message" rows="5" cols="50"></textarea></p>
    <p>Your Email:
    <input name="email" type="text" /></p>
    <p><input type="submit" value="Send Feedback" /></p>
    </div>
    </form>


    SendFeedback.ph p

    <?php

    //get the senders email

    $from = $_REQUEST['email'] ;

    //define the receiver of the email

    $to = 'support@mysite .com';

    // subject of the email

    $subject = 'Feedback Form Results';

    //define the message to be sent.

    $message = $_REQUEST['message'] ;

    //define the headers

    $headers = "From: '$from'\r\nRepl y-To: '$from' ";

    //send the email

    $mail_sent = @mail( $to, $subject, $message, $headers );

    echo $mail_sent ? "<br><font face='Verdana' size='3' color='green'>M ail sent, Thank You for your Feedback</font>" : "<br><font face='Verdana' size='3' color='green'>M ail failed</font>";

    ?>[/php]
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #2
    Originally posted by phpmind
    I am attempting to send and email via my feedback form and nothing seems to go thru. I have tried sending to a yahoo account and a gmail account. I have changed a few things in my script several times and did receive a couple emails about 1 day later that just went into bulk. As of now I receive nothing. Can someone please take a look at my script and tell me what I am doing wrong. Also how do I prevent mails from going to bulk/spam? Could this be an issue with my web hosting company ?

    Form.php

    <form method="post" action="sendfee dback.php">
    <div align="center">
    <p align="center"> <font face='Verdana' >Contact Us</font> </p>
    <p>Feedback<b r>
    <textarea name="message" rows="5" cols="50"></textarea></p>
    <p>Your Email:
    <input name="email" type="text" /></p>
    <p><input type="submit" value="Send Feedback" /></p>
    </div>
    </form>


    SendFeedback.ph p

    <?php

    //get the senders email

    $from = $_REQUEST['email'] ;

    //define the receiver of the email

    $to = 'support@mysite .com';

    // subject of the email

    $subject = 'Feedback Form Results';

    //define the message to be sent.

    $message = $_REQUEST['message'] ;

    //define the headers

    $headers = "From: '$from'\r\nRepl y-To: '$from' ";

    //send the email

    $mail_sent = @mail( $to, $subject, $message, $headers );

    echo $mail_sent ? "<br><font face='Verdana' size='3' color='green'>M ail sent, Thank You for your Feedback</font>" : "<br><font face='Verdana' size='3' color='green'>M ail failed</font>";

    ?>
    This is not right.
    $to = 'support@mysite .com';
    $subject = 'Feedback Form Results';

    try this instead
    $EmailTo = "support@mysite .com";
    $subject = "Feedback Form Results";

    then
    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>" );


    nomad
    ps I think
    echo $mail_sent ? statement is wrong to....

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Next time enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

      moderator

      Comment

      • phpmind
        New Member
        • Feb 2008
        • 16

        #4
        Tried what you gave me. Still no email. Any other suggestions are appreciated.

        Comment

        • nomad
          Recognized Expert Contributor
          • Mar 2007
          • 664

          #5
          Originally posted by phpmind
          I am attempting to send and email via my feedback form and nothing seems to go thru. I have tried sending to a yahoo account and a gmail account. I have changed a few things in my script several times and did receive a couple emails about 1 day later that just went into bulk. As of now I receive nothing. Can someone please take a look at my script and tell me what I am doing wrong. Also how do I prevent mails from going to bulk/spam? Could this be an issue with my web hosting company ?

          Form.php
          [php]
          <form method="post" action="sendfee dback.php">
          <div align="center">
          <p align="center"> <font face='Verdana' >Contact Us</font> </p>
          <p>Feedback<b r>
          <textarea name="message" rows="5" cols="50"></textarea></p>
          <p>Your Email:
          <input name="email" type="text" /></p>
          <p><input type="submit" value="Send Feedback" /></p>
          </div>
          </form>


          SendFeedback.ph p

          <?php

          //get the senders email

          $from = $_REQUEST['email'] ;

          //define the receiver of the email

          $to = 'support@mysite .com';

          // subject of the email

          $subject = 'Feedback Form Results';

          //define the message to be sent.

          $message = $_REQUEST['message'] ;

          //define the headers

          $headers = "From: '$from'\r\nRepl y-To: '$from' ";

          //send the email

          $mail_sent = @mail( $to, $subject, $message, $headers );

          echo $mail_sent ? "<br><font face='Verdana' size='3' color='green'>M ail sent, Thank You for your Feedback</font>" : "<br><font face='Verdana' size='3' color='green'>M ail failed</font>";

          ?>[/php]
          Not sure if php is case-senative
          Code:
          <form method="post" action="sendfeedback.php">
          change to
          Code:
           <form method="POST" action="SendFeedback.php">
          this might be wrong
          Code:
          <input type="submit" value="Send Feedback" />
          try this
          Code:
          <input type="submit" name="submit" value="Submit">
          you might want to add this section after you posted data into local variables.
          Code:
          // validation
          $validationOK=true;
          if (!$validationOK) {
            print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
            exit;
          }
          Which brings up at matter you have no $_POST sections.



          still not to sure about this part
          echo $mail_sent ? "<br><font face='Verdana' size='3' color='green'>M ail sent, Thank You for your Feedback</font>" : "<br><font face='Verdana' size='3' color='green'>M ail failed</font>";


          nomad

          Comment

          • phpmind
            New Member
            • Feb 2008
            • 16

            #6
            I contacted my web hosting company and their is a piece of code they gave me that has to be inserted before the mail( ) function. Wish I knew this before. Thanks for your help ! It is working now.

            Comment

            • nomad
              Recognized Expert Contributor
              • Mar 2007
              • 664

              #7
              Originally posted by phpmind
              I contacted my web hosting company and their is a piece of code they gave me that has to be inserted before the mail( ) function. Wish I knew this before. Thanks for your help ! It is working now.

              Good job...
              if you wish to share that info it might help others that might have the same problem

              nomad

              Comment

              • yasmine
                New Member
                • Feb 2008
                • 64

                #8
                Originally posted by phpmind
                I contacted my web hosting company and their is a piece of code they gave me that has to be inserted before the mail( ) function. Wish I knew this before. Thanks for your help ! It is working now.
                Hi phpmind,

                Could u please send me the piece of code given by the web hosting company?
                I'm also having the same problem.......
                Plz... help me out....

                Thanx n Regards
                Yas

                Comment

                • phpmind
                  New Member
                  • Feb 2008
                  • 16

                  #9
                  I was told to insert this code right before the mail () function is executed.

                  Where 'user@domain.co m' should be a valid email address associated with the domain name for example (postmaster@mys ite.com)

                  //initialize mail function for web host
                  <? ini_set('sendma il_from', 'user@domain.co m' ); ?>

                  Hope this helps!

                  Comment

                  • yasmine
                    New Member
                    • Feb 2008
                    • 64

                    #10
                    Originally posted by phpmind
                    I was told to insert this code right before the mail () function is executed.

                    Where 'user@domain.co m' should be a valid email address associated with the domain name for example (postmaster@mys ite.com)

                    //initialize mail function for web host
                    <? ini_set('sendma il_from', 'user@domain.co m' ); ?>

                    Hope this helps!

                    Hi,
                    Thanx 4 ur reply.

                    But i'm not sure where to put this code.
                    Where it should be present whether 'sendfeedback.p hp' or 'feedback.html' ?
                    What is meant by 'sendmail_from' ?

                    I put it in sendfeedback.ph p, but the same thing is happened again.(I got the message "Mail Failed" as output.)

                    Could you please explain...??

                    Thanx n Regards
                    Yas

                    Comment

                    • Markus
                      Recognized Expert Expert
                      • Jun 2007
                      • 6092

                      #11
                      Originally posted by yasmine
                      Hi,
                      Thanx 4 ur reply.

                      But i'm not sure where to put this code.
                      Where it should be present whether 'sendfeedback.p hp' or 'feedback.html' ?
                      What is meant by 'sendmail_from' ?

                      I put it in sendfeedback.ph p, but the same thing is happened again.(I got the message "Mail Failed" as output.)

                      Could you please explain...??

                      Thanx n Regards
                      Yas
                      This is because it's relative to only the OP's (original poster) server.

                      You might not be running the same PHP.

                      Comment

                      • phpmind
                        New Member
                        • Feb 2008
                        • 16

                        #12
                        This code would go directly before your mail() function. As the last post states it may be different for your web server/php environment. If you continue to have problem I would suggest contacting your service provider if all else fails.

                        Comment

                        Working...