简体   繁体   中英

php contact form works but wont send to one specific email

I have this contact form working with my email but when i put in the clients email it wont send the mail, We both use the same godaddy workspace email program and Im out of ideas! can anyone help me.

PS

Im using PHP Mailer script with this code

<?php
    /* Form Handling Code */

    // Check if form has been submitted.
    // if the $_POST["email"] variable exists,
    // then the form HAS been submitted already.

    $errors = array( "unsubmitted" => TRUE );

    if( isset( $_POST[ "email" ] ) )
    {
        if( strlen( $_POST[ "email" ] ) > 0 )
        {
            // there was something typed in the email field
            if( strlen( $_POST[ "message" ] ) > 0 )
            {
                // there was something typed in the message field

                require_once( "includes/class.phpmailer.php" );

                // create an instance of the PHPMailer object
                $mail = new PHPMailer();

                // send the email, everything is OK.

                $subject = "Contact Form Email";

                $to = "info@companyname.com";

                $message = "Name: ".mb_strtolower($_POST['name'])." <br /> Telephone:    ".$_POST['telephone']." <br /> E-Mail:    ".$_POST['email']." <br /> Enquiry:    ".$_POST['enquiry']." <br /> Message:    ".$_POST['message']."";

                $enquiry = "Enquiry: {$_POST["enquiry"]}";

                $telephone = "Telephone: {$_POST["telephone"]}";

                $from = filter_var( $_POST[ "email" ], 
                                        FILTER_VALIDATE_EMAIL );

                if( !$from )
                {
                    $errors[ "email" ] = "<p class=\"error\">
                                            Please enter a valid email address.
                                          </p>";
                }

                if( count( $errors ) < 2 )
                {
                    $mail->AddAddress( $to, "Fun Guy" );
                    $mail->SetFrom( $_POST["email"] );
                    $mail->AddReplyTo( $_POST["email"] );
                    $mail->Subject = $subject;
                    $mail->MsgHTML( $message );
                    $mail->AltBody = $message ;

                    if( !$mail->Send() )
                    {
                        $sendError = "<p>{$mail->ErrorInfo}</p>";
                    }
                    else
                    {
                        // clear the first "default" error
                        unset( $errors[ "unsubmitted" ] );
                    }
                }
            }
            else
            {
                $errors[ "message" ] = "<p class=\"error\">
                                            Please enter a message.
                                        </p>";
            }
        }
        else
        {
            $errors[ "email" ] = "<p class=\"error\">
                                    Please enter an email address
                                  </p>";
        }
    }
?>






<div id="contactpageleft">
        <p class="title">Send Us A Message</p>
        <div id="contact-form" class="clearfix">
    <?php if( count( $errors ) > 0 ): ?>
    <?php echo $sendError; ?>
    <form id="formID" action="" class="formular" method="post">
        <?php echo $_POST["name"]; ?>
        <label for="name">Name:</label>
        <input value="<?php echo $_POST["name"]; ?>" type="text" id="name" name="name" value="" placeholder="John Doe" required autofocus />

        <?php echo $errors[ "email" ]; ?>
        <label for="email">Email Address:</label>
        <input value="<?php echo $_POST["email"]; ?>"  type="email" id="email" name="email" value="" placeholder="johndoe@example.com" required />

        <?php echo $errors[ "telephone" ]; ?> 
        <label for="telephone">Telephone: </label>
        <input value="<?php echo $_POST["telephone"]; ?>" type="telephone" id="telephone" name="telephone" value="" />

        <?php echo $errors[ "enquiry" ]; ?> 
        <label for="enquiry">Enquiry: </label>
        <select type="enquiry" id="enquiry" name="enquiry" value="" id="enquiry" name="enquiry">
            <option value="General">General</option>
            <option value="Sales">Sales</option>
            <option value="Support">Support</option>
        </select>

        <?php echo $errors[ "message" ]; ?> 
        <label for="message">Message: </label>
        <textarea id="message" name="message" placeholder="Your message must be greater than 20 charcters" required data-minlength="20"><?php echo $_POST["message"]; ?></textarea>


        <input class="submit" type="submit" value="SEND EMAIL" />

    </form>
    <?php else: ?>
        <h2>Your email was sent successfully!</h2>
    <?php endif; ?>
</div>
    </div>

Firstly you've based your code on an obsolete example and are probably using an old version of PHPMailer, so get the latest .

You're forging the From address, which will prevent delivery on many systems as it will cause SPF failures. Put your own address in the From address and put the submitter's address in a reply-to.

You're calling msgHTML , so there's no need to set AltBody as well.

GoDaddy is well known for blocking outbound SMTP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM