<?php

$YourEmailAddress = '888@8888.com'; //
$Yourname = '8888'; //
$MailUsername ='8888@8888'; //
$MailPassword = '8888'; //
$MailServer = 'mail.8888.com'; //
$MailType = 'TEXT'; //

require("c:\php\includes\class.phpmailer.php"); //



if ($_POST['email']) {
$action = $_POST["action"];
$name = $_POST["name"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$comments = $_POST["comments"];

if(strtolower($MailType) == 'html'){
$mailtypetosend = true;
} else {
$mailtypetosend = false;
}

$mail = new PHPMailer();

$mail->From = $email;
$mail->FromName = $email;
$mail->Host = $MailServer;
$mail->Mailer = "smtp";

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = $MailUsername; // SMTP username
$mail->Password = $MailPassword; // SMTP password

$mail->AddAddress($YourEmailAddress, $Yourname);
$mail->AddReplyTo($ReplyToEmailAddress, $ReplyToEmailname);

$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML($mailtypetosend); // True for HTML, FALSE for plain text
$mail->SetLanguage("en", "language/");

//Start the page action upon submittal
if ($action == "contact" ) {
if (empty($_POST['name'])) {
$name = FALSE;
$message .= '<br>Please enter your name</br>';
} else {
$name = $_POST['name'];
}
if (empty($_POST['phone'])) {
$phone = FALSE;
$message .= '<br>Please enter a phone number to reach you at</br>';
} else {
$phone = $_POST['phone'];
}
if (empty($_POST['email'])) {
$email = FALSE;
$message .= '<br>Please enter your email address</br>';
} else {
$email = $_POST['email'];
}
if (empty($_POST['comments'])) {
$comments = FALSE;
$message .= '<br>You did not enter in a message</br>';
} else {
$comments = $_POST['comments'];
}

if($comments && $email && $phone && $name){

$mail->Subject = "Contact Us form submitted";
$mail->Body = "A contact us form has been submitted from the website\nHere are the

details:\n\n\n";
$mail->Body .= "Name: $name \n";
$mail->Body .= "Phone number: $phone\n";
$mail->Body .= "Email Address: $email\n";
$mail->Body .= "Message: $comments\n\n\n";

if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
} else {
$sent = 1;
}


echo "<table width=\"622\" border=\"0\" align=\"center\" class=\"table01\">
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Thank you for contacting us,

We will respond to all inquiries in the order as they are received, as soon as it is

possible.</span></td>
</tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Name: $name</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Email Address:

$email</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Phone Number:

$phone</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"center\">Message: $comments</span></td>
</tr>
<tr>
</table>";
}
}
if(isset($message)) {echo "<center><u><b>$message</span></b></u></center><br>";}
} else { die("Missing Email Address."); }
if($sent != 1){
echo "
<table width=\"424\" border=\"0\" align=\"center\" >
<form name=\"form1\" method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<input type=\"hidden\" name=\"action\" value=\"contact\">
<tr>
<td colspan=\"2\">Contact Form</td>
</tr>
<tr>
<td>Name</td>
<td>
<input name=\"name\" type=\"text\" value=\"$name\">
</td>
</tr>
<tr>
<td>Email Address </td>
<td><input name=\"email\" type=\"text\" value=\"$email\"></td>
</tr>
<tr>
<td>Phone Number </td>
<td><input name=\"phone\" type=\"text\" value=\"$phone\"></td>
</tr>
<tr>
<td height=\"86\">Message / Comments </td>
<td><textarea name=\"comments\" cols=\"30\" rows=\"5\" value=\"$comments\"></textarea>
</td>
</tr>
<tr>
<td height=\"20\" colspan=\"2\"><center><input type=\"submit\" name=\"Submit\" value=\"Submit\">
</center></td>
</tr>
</form>
</table>";
}


?> 

    Nog you're a star. It does look pretty, but unfortunately I still get an error. 🙁

    Parse error: syntax error, unexpected $end in mailer.php on line 187

      Thanks phaseone. I tried yours as well and I get a dif error..

      Notice: Undefined index: email in mailer.php on line 15
      Missing Email Address.

      god hates me 🙁

      lol

        tim_4211 wrote:

        Nog you're a star. It does look pretty, but unfortunately I still get an error. 🙁

        Parse error: syntax error, unexpected $end in mailer.php on line 187

        I didn't fix anything, just was trying to help you see the current structure so you could decide where you wanted to close the open if block, depending on what logical flow you wanted to implement.

          :o ... thats how much I know about php.

          I don't know where to close the if block because I don't fully understand what an if block is. I'm assuming if the info is not filled in where its required by the script then the "if" will redirect the user to fill it in? Then it should go after

          $comments = $_POST['comments'];
          }

            See if this is any better (and if you can follow the logic flow, as I've shifted things around a lot):

            <?php
            // populate form variables if they are set:
            $name = (isset($_POST['name'])) ? trim($_POST['name']) : '';
            $phone = (isset($_POST['phone'])) ? trim($_POST['phone']) : '';
            $email = (isset($_POST['email'])) ? trim($_POST['email']) : '';
            $comments = (isset($_POST['comments'])) ? trim($_POST['comments']) : '';
            $sent = false;
            
            // only process form if we got an action from POST
            if(isset($_POST['action']) and $_POST['action'] == 'contact')
            {
               // make sure all fields have data:
               $requiredFields = array('name', 'phone', 'email', 'comments');
               $errors = array(); // to hold any error messages
               foreach($requiredFields as $field)
               {
                  if(!isset($_POST[$field]) or trim($field) === "")
                  {
                     $errors[] = ucwords($field) . " is a required field.";
                  }
               }
               if(count($errors) == 0) // no errors, so go ahead with mailing
            
               {
                  $YourEmailAddress = '888@8888.com'; //
                  $Yourname = '8888'; //
                  $MailUsername = '8888@8888'; //
                  $MailPassword = '8888'; //
                  $MailServer = 'mail.8888.com'; //
                  $MailType = 'TEXT'; //
                  require ("c:\php\includes\class.phpmailer.php"); //
            
              if(strtolower($MailType) == 'html')
              {
                 $mailtypetosend = true;
              }
              else
              {
                 $mailtypetosend = false;
              }
            
              $mail = new PHPMailer();
            
              $mail->From = $email;
              $mail->FromName = $email;
              $mail->Host = $MailServer;
              $mail->Mailer = "smtp";
            
              $mail->SMTPAuth = true; // turn on SMTP authentication
              $mail->Username = $MailUsername; // SMTP username
              $mail->Password = $MailPassword; // SMTP password
            
              $mail->AddAddress($YourEmailAddress, $Yourname);
              $mail->AddReplyTo($ReplyToEmailAddress, $ReplyToEmailname);
            
              $mail->WordWrap = 50; // set word wrap to 50 characters
              $mail->IsHTML($mailtypetosend); // True for HTML, FALSE for plain text
              $mail->SetLanguage("en", "language/");
            
              $mail->Subject = "Contact Us form submitted";
              $mail->Body = "A contact us form has been submitted from the website\nHere are the
            
            details:\n\n\n";
                  $mail->Body .= "Name: $name \n";
                  $mail->Body .= "Phone number: $phone\n";
                  $mail->Body .= "Email Address: $email\n";
                  $mail->Body .= "Message: $comments\n\n\n";
            
              if(!$mail->Send())
              {
                 $errors[] = "Message could not be sent: " . $mail->ErrorInfo;
              }
              else
              {
                 echo "<table width=\"622\" border=\"0\" align=\"center\" class=\"table01\">
            <tr>
            <td width=\"526\" class=\"OutlineOne\" align=\"center\">Thank you for contacting us,
            
            We will respond to all inquiries in the order as they are received, as soon as it is
            
            possible.</span></td>
            </tr>
            <tr>
            <td width=\"526\" class=\"OutlineOne\" align=\"center\">Name: $name</span></td>
            </tr>
            <tr>
            <tr>
            <td width=\"526\" class=\"OutlineOne\" align=\"center\">Email Address:
            
            $email</span></td>
            </tr>
            <tr>
            <tr>
            <td width=\"526\" class=\"OutlineOne\" align=\"center\">Phone Number:
            
            $phone</span></td>
            </tr>
            <tr>
            <tr>
            <td width=\"526\" class=\"OutlineOne\" align=\"center\">Message: $comments</span></td>
            </tr>
            <tr>
            </table>";
                  }
               }
            }
            if(isset($message))
            {
               echo "<center><u><b>$message</span></b></u></center><br>";
            }
            
            if($sent != 1)
            {
               echo "
            <table width=\"424\" border=\"0\" align=\"center\" >
            <form name=\"form1\" method=\"post\" action=\"$_SERVER[PHP_SELF]\">
            <input type=\"hidden\" name=\"action\" value=\"contact\">
            <tr>
            <td colspan=\"2\">Contact Form</td>
            </tr>
            <tr>
            <td>Name</td>
            <td>
            <input name=\"name\" type=\"text\" value=\"$name\">
            </td>
            </tr>
            <tr>
            <td>Email Address </td>
            <td><input name=\"email\" type=\"text\" value=\"$email\"></td>
            </tr>
            <tr>
            <td>Phone Number </td>
            <td><input name=\"phone\" type=\"text\" value=\"$phone\"></td>
            </tr>
            <tr>
            <td height=\"86\">Message / Comments </td>
            <td><textarea name=\"comments\" cols=\"30\" rows=\"5\" value=\"$comments\"></textarea>
            </td>
            </tr>
            <tr>
            <td height=\"20\" colspan=\"2\"><center><input type=\"submit\" name=\"Submit\" value=\"Submit\">
            </center></td>
            </tr>
            </form>
            </table>";
            }
            ?> 
            

              It works! kinda! I'm still getting some errors.

              Notice: Undefined variable: ReplyToEmailAddress in mailer.php on line 57

              Notice: Undefined variable: ReplyToEmailname in mailer.php on line 57

              Thanks for all your help though. I'll buy you a beer/coffee if you ever come to Seattle 😃

                add this

                $YourEmailAddress="my@email.com";
                $Yourname="myName";
                $ReplyToEmailAddress="my@email.com";
                $ReplyToEmailname="myName";
                

                before this

                $mail->AddAddress($YourEmailAddress, $Yourname);
                $mail->AddReplyTo($ReplyToEmailAddress, $ReplyToEmailname);
                

                so it looks like this

                $YourEmailAddress="my@email.com";
                $Yourname="myName";
                $ReplyToEmailAddress="my@email.com";
                $ReplyToEmailname="myName";
                $mail->AddAddress($YourEmailAddress, $Yourname);
                $mail->AddReplyTo($ReplyToEmailAddress, $ReplyToEmailname);
                

                  Thanks phaseone. The errors went away but the email is still not always going through. One of my 3 email accounts works, but the other 2 and my hotmail account don't go through.

                    hotmail is stubborn. It is probably in your junk box or it was automatically deleted. Since it went to your other email accounts, you know that it is not your script, but Hotmail.

                      Another update.

                      I ended up getting it to work with all of my emails, including the hotmail, ONCE. It works randomly.. I seem to be able to ALWAYS get it to work with the email I used in the the script. But its hit or miss with the rest .. also had a friend test it with a gmail and it didn't go through..

                        Write a Reply...