Whats wrong with this code!

Ok I’ve run that test, adding in the echo commands but its made no difference, - I still just receive the same message ‘There was a problem with sending the form…’ I don’t understand why its not making any difference!

This is the link they sent me with the example scripts: http://eurofasthost.com/support/knowledgebase/sendemail_SMTP.asp

This is the example phpMailer one:

IsSMTP(); // set mailer to use SMTP $mail->Host = "mail.domain.com"; // specify main and backup server $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "outbound@domain.com"; // SMTP username $mail->Password = "password"; // SMTP password // Set Sender/Recipient $mail->From = "contactform@domain.com"; $mail->FromName = "From Name"; $mail->AddAddress("info@domain.com", "Domain name"); //Address of recipient // Build Message Body $msg = " Name: $name Email: $email Telephone: $telephone Message: $message "; // Set Subject + Body + Settings $mail->Subject = "Subject Title"; $mail->Body = $msg; $mail->WordWrap = 50; // set word wrap to 50 characters // Send Message and Report if(!$mail->Send()) { echo "Message could not be sent. 
"; echo "Mailer Error: " . $mail->ErrorInfo; exit; } echo "Mail was sent thank you!"; echo sprintf("
Go Back ",$_SERVER['HTTP_REFERER']); ?> 

Thanks

So you didn’t get any additional verbiage at the top of the page after completing the form?

No nothing additional, just the same error message as before…

Okay, let’s add a bit more debugging data, place this at the top of your script:

if ($_POST) {
    if ($_POST["name"] && preg_match("/^[a-zA-Z0-9 ]+$/i", $_POST["name"]) === false) {
      die("failed to validate the name");
    }
    if ($_POST["email"] && preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i", $_POST["email"]) === false) {
      die("failed to validate the e-mail");
    }
}

it’s still not changing anything! Am I doing something wrong here?

You are uploading your new script to the server/host right? As you should be seeing one of the die statements or a message at the top of your page stating it is attempting to send the email.

Yes I’m changing the script then uploading it to the host, refresh the website enter the details but still receive the same result

&

Okay, change the following statement

if ($_POST && $_POST["name"] && preg_match("/^[a-zA-Z0-9 ]+$/i", $_POST["name"]) && $_POST["email"] && preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i", $_POST["email"])) {

To

if ($_POST && $_POST["name"] && preg_match("/^[a-zA-Z0-9 ]+$/i", $_POST["name"]) !== false && $_POST["email"] && preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i", $_POST["email"]) !== false) {

Right now were getting somewhere, - I get the message Attempting to send e-mail…Failed! at the top of the page

:slight_smile: okay, start off by downloading phpMailer (I’m not sure you’ll need this if you host installed phpMailer properly, but you may if they didn’t).

Update your mail logic

    
    include_once('class.phpmailer.php');
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = ""; // place your smtp host here
    $mail->SMTPAuth = true;
    $mail->Username = "" // place your smtp username here
    $mail->Password = "" // place your smtp password here

    $mail->From = $_POST["email"];
    $mail->FromName = $_POST["name"];
    $mail->AddAddress("enquiries@.co.uk");

    $mail->Subject = "Enquiry from the  Website";

    // build the email
    $s = "The following contact form has been submitted:\
\
";

    $s .= "=== Customer Details =====\
";
    $s .= "Name: " .$_POST["name"]. "\
";
    $s .= "Company: " .$_POST["company"]. "\
";
    $s .= "Telephone: " .$_POST["telephone"]. "\
";
    $s .= "Email Address: " .$_POST["email"]. "\
\
";

    $s .= "=== Enquiry Information =====\
";
    $s .= trim($_POST["comments"])."\
\
";

    $s.= "Generated: " .date("Y-m-d H:i:s");

    $mail->Body = $s;
    $mail->WordWrap = 72;

    echo "Attempting to send e-mail...";
    if ($mail->Send()) {
        $SENT = true;
        echo "Success!";
    } else {
        $SENT = false;
        echo "Failed!";
    }

Ok, dont think I need the mailer as its on the host but what do I do with that code, - add it to the existing script or a new one? & if add to existing, where abouts does it go & do I have to remove anything?

<?php

$SENT = false;
if ($_POST && $_POST["name"] && preg_match("/^[a-zA-Z0-9 ]+$/i", $_POST["name"]) !== false && $_POST["email"] && preg_match("/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$/i", $_POST["email"]) !== false) {

    include_once('class.phpmailer.php');
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = ""; // place your smtp host here
    $mail->SMTPAuth = true;
    $mail->Username = "" // place your smtp username here
    $mail->Password = "" // place your smtp password here

    $mail->From = $_POST["email"];
    $mail->FromName = $_POST["name"];
    $mail->AddAddress("enquiries@.co.uk");

    $mail->Subject = "Enquiry from the  Website";

    // build the email
    $s = "The following contact form has been submitted:\
\
";

    $s .= "=== Customer Details =====\
";
    $s .= "Name: " .$_POST["name"]. "\
";
    $s .= "Company: " .$_POST["company"]. "\
";
    $s .= "Telephone: " .$_POST["telephone"]. "\
";
    $s .= "Email Address: " .$_POST["email"]. "\
\
";

    $s .= "=== Enquiry Information =====\
";
    $s .= trim($_POST["comments"])."\
\
";

    $s.= "Generated: " .date("Y-m-d H:i:s");

    $mail->Body = $s;
    $mail->WordWrap = 72;

//    echo "Attempting to send e-mail...";
    if ($mail->Send()) {
        $SENT = true;
//        echo "Success!";
    } else {
        $SENT = false;
//        echo "Failed!";
    } 
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

<head>
    <title></title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta http-equiv="imagetoolbar" content="no" />
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <meta name="revisit-after" content="7 days">
    <meta name="Copyright" content="Beverley Morris">
    <meta name="Robots" content="all">
    <meta name="language" content="en">
    <meta name="distribution" content="Global">

    <link rel="shortcut icon" href="/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="css/print.css" media="print" />

    <style type="text/css" media="screen">
    <!--
    @import url(css/styles.css);
    -->
    </style>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script> 
    <script src="js/jquery-1.5.1.min.js" type="text/javascript"></script>
     <script src="js/global.js" type="text/javascript"></script>
    <script src="js/jquery.goomaps.js" type="text/javascript"></script>
    
    
    
    
</head>

<body>

<div id="container_header">
    <div id="header">

    <div id="logo"><h1><a href="/" title="Home"><span></span></a></h1></div>

    <div id="header-right">
    <div id="contact">
    Tel: 020   Fax: 020 <br />
    Email: <a href="mailto:enquiries@.co.uk">enquiries@.co.uk</a>
    </div>
    </div>

    <div id="navigation">
        <ul class="navInner">
            <li><a href="/">Homepage</a></li>
            <li><a href="about-us.htm" >About Us</a></li>
            <li>
                <a href="our-services.htm">Our Services</a>
                <ul>
                    
                </ul>
            </li>
            <li>
                <a href="team-profiles.htm" >Team Profiles</a>
                <ul>
                    
                </ul>
            </li>

        <li><a href="contact.php" class="active">Contact Us</a></li>
        </ul>
    </div>

    </div>
</div>
    
<div id="container_body">
    <div id="body">
        
        <div class="clearboth">&nbsp;</div>


        <div id="home_panel">

            <div id="home_bottompanel_content">

            <h2>Contact Us</h2>
        
            <div class="goomapsWrapper">
                <h3>Office</h3>
                <p>
                    <br />
                    <br />
                    <span>T:</span> +44 020 <br />
                    <span>F:</span> +44 020 <br />
                    <span>DX:</span> <br />
                    <span>E:</span> <a href="mailto:enquiries@.co.uk">enquiries@.co.uk</a>
                    
                </p>    
                <div id="map_canvas" class="map_canvas"></div>    
            </div>
            <div class="goomapsWrapper">
                <h3>Office</h3>
                <p>

                    <br />
                    <br />
                    <span>E:</span> <a href="mailto:.co.uk">.co.uk</a>
                </p>                    
                <div id="map_canvas2" class="map_canvas"></div>                    
            </div>            

            <div>
            <?php if (!$SENT) { ?>

            <?php if (!$SENT && $_POST) { 
                echo '<p class="red">There was a problem with sending the form.<br />Please check to ensure you have filled in all the fields.</p>';
            } ?>
            <p><b>Enquiry Form</b><br />
            <span class="red">**</span> Indicates required fields</p>
            
            <form name="contact" action="contact.php" method="post">
            <fieldset class="conform">
            <legend>Your Details</legend><br />
            <label for="name">Name</label>
            <input id="name" type="text" size="40" value="<?php echo (isset($_POST["name"])) ? $_POST["name"] : '' ; ?>" name="name" /> <span class="red">**</span><br />
            <label for="company">Company</label>
            <input id="company" type="text" size="40" value="<?php  echo (isset($_POST["company"])) ? $_POST["company"] : '' ; ?>" name="company" /><br />
            <label for="telephone">Telephone</label>
            <input id="telephone" type="text" size="40" value="<?php echo  (isset($_POST["telephone"])) ? $_POST["telephone"] : ''; ?>" name="telephone" /><br />
            <label for="email">Email Address</label>
            <input id="email" type="text" size="40" value="<?php echo (isset($_POST["email"])) ? $_POST["email"] : ''; ?>" name="email" /> <span class="red">**</span><br />
            </fieldset>

            <fieldset class="conform2">
            <legend>Further Information</legend><br />
            <textarea id="comments" name="comments" size="40" rows="8" cols="50"><?php  echo(isset($_POST["comments"])) ? $_POST["comments"] : '' ; ?></textarea>
            </fieldset>

            <br />
            <a href="javascript:document.contact.submit();"><img title="" height="43" alt="" src="images/submit.gif" width="102" border="0" /></a>
            </form>
            </div>

            <?php
                } else {
            ?>
            <p>Thank you for your enquiry. We will reply as soon as possible.</p>
            <?php
                }
            ?>

        </p>

            </div>
        </div>
        
        <div id="ftr">
        <span id="copyright">Copyright &copy; <br />
        Tel: 020 8852 4433 &nbsp;  Fax: 020 8463 9494 &nbsp; Email: <a href="mailto:enquiries@b.co.uk">enquiries@.co.uk</a></span>
        <span id="ftr_links"><a href="terms.htm">Terms of Use</a> <a href="privacy.htm">Privacy Policy</a> <a href="http://www..co.uk" title="Cambridge Web Design and Development by" target="_blank" class="last">Web Design by </a></span>
        <div class="clearboth">&nbsp;</div>
        </div>
        
    </div>

     <script>
         $(document).ready(function(){
         $('#map_canvas').goomaps("init", { 
            center: [51.467434,0.008308],
            zoom: 16,
                clickable: true,
                draggable: true,
                scrollwheel: false,
            OverviewMapControlOptions: false,
         }).goomaps("addmarkers", [{ options: {
                position: [51.467434,0.008308]

                
                
         }}]);
         $('#map_canvas2').goomaps("init", { 
            center: [51.462998,-0.010772],
            zoom: 16,
                clickable: true,
                draggable: true,
                scrollwheel: false,
            OverviewMapControlOptions: false,
         }).goomaps("addmarkers", [{ options: {
                position: [51.462998,-0.010772]

                
         }}]);         
      });
     </script>

</body>
</html>

Hmm this is what happened before when I tried to add similar code, - the page is now not displayed, - just a blank white page…

After submitting the form?

Add

ini_set('display_errors', 1);

To the top of your script

No, I cant even access the page now to fill in the form, made changes, uploaded, refreshed page and nothing, just blank white page

Do you have access to error logs? If so, look in there for why it is showing a blank page.

No I don’t have access to the logs. As soon as I add that phpMailer code in, the page is blank. Take it out & its all ok again!

try commenting out the include_once line and see if the blank page happens

its the $mail->Username = and $mail->Password = lines that are casuing the problem, - the page is fine if I connect these two out, add them back in & its blank!

hmm… I got that from your hosts example, weird… so I’d ask them about it. Also, you should ask them about access to error logs, as you should have the ability to view those.