Jump to content

Recommended Posts

Posted

I am looking for a PHP tutorial or a script to write a small email contact form in OOP not the procedural method. I would like to use the mail server connected to my hosting services as opposed to sending it through Google. As anyone seen this?

Thanks!

WBR

Posted

I'm not sure you are going to be able to find exactly what you are looking for. You're probably better off looking for some basic OOP understanding (I know Stefan has a video or two on it) and then apply that knowledge to create a contact script.

Posted

Benjamin:

Thanks for responding. You are probably correct in saying that I will not find exactly what I am looking for since I searched the web this morning for the tutorial or file that I wrote about here. I took a look at Stefan video last night. I am well experienced in the OOPs world having coded in C++ and Java for far too many years. The web is new to me and in my PHP code that I wrote to exercise my knowledge in PHP OPP still has a few glitches that I cant resolve and can?t find an answer in the PHP mail package documentation, so I thought I would give it a try here since you folks have been REALLY helpful to me. If you have any pull with Stefan ask him to stop what he is doing and jump to a tutorial on PHP OOPs contact form.

Thanks!

WBR

Posted

Monkeysaurus:

I will post this soon. I am almost there. I finally got mail to come to me but the contents are not what I thought I was sending and I don't know how to work the PHP debugger in this system so it's taking a while.

WBR

Posted

Well I got this to work.

First this is modifying a procedural PHP script that I found some time ago with a OPPs PHP tutorial that I saw maby a week ago and stuffing the procedural script into the OOP version.

I tested in my developing environment and I can send emails from my home machine and then the emails are redirected back to my mail box. I don?t see why it won?t work on my site but I will put it up there tomorrow and check.

The routine required me to create an account that I left in place so that it reads better where the username email and passwords go.

There are two files. The style sheet is not enclosed in this email but if you ignore the HTML you should be able to follow the flow of the contact form that collects the information is sent to a second file that checks some parameters and concatenates others and sends the file. It?s not a big deal if you know PHP, but I don?t.

One more thing I just realized that I did not mention the second file needs presentation, I did not put that in yet.

contactform.php










   content="software engineer, web development, graphics, website design, PHP, MySQL, Java, JavaScript, HTML, CSS," />
   content="The Home page of William Bradley Rouse. Includes software and work description." />







   content="Copyright ? 2008 William Bradley Rouse. All Rights Reserved." />



W. Bradley Rouse - About Me 
















   <?php include("include/branding.inc"); ?>



   <?php include("include/leftContent.inc"); ?>



 Contact Form

 All Fields required




<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>





OOP Contact Form




Name: 

Email Address: 

Phone: 

Attention:

Web Developoment 
Web Related Assistance 
Java Assistance 
Technical Support 
Employment
Photography
Hobbies


Time of day to call back:

Morning
After Noon
Evening


Questions/Comments:     












 

sendEmail02.php

<?php
   // This won't except comments with http in it?
if (eregi('http:', $notes)) {
   die ("Do NOT try that! ! ");
}
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$name = trim ($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$attn = trim($_POST['attn']);
$con_time = trim($_POST['con_time']);
$comments = trim($_POST['comments']);

$site_owners_email = 'mailer@rouse.ws'; // Replace this with your own email address
$site_owners_name = 'William Rouse'; // replace with your name

// Cheap check for a vaild name
if (strlen($name) < 2) {
   $error['name'] = 'Please enter your name';
}

   // check for a valid email address [have no idea how this works
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
   $error['email'] = "Please enter a valid email address";
}

// check for a valid comment
if (strlen($comments) < 3) {
   $error['comments'] = 'Please leave a comment.';
}

if (!$error) {

   require_once ('phpMailer/class.phpmailer.php'); // bring in the include file
   $todayis = date("l, F j, Y, g:i a") ;           //get todays date
   $myMail = new PHPMailer();     

   $myMail->From = $email;
   $myMmail->FromName = $name;
   $myMail->Subject = 'Website Contact Form';
   $myMail->AddAddress($site_owners_email, $site_owners_name);
   $myMail->AddAddress('mailer@rouse.ws');
   $myMail->Body = "$todayis [CST] \n
                   Attention: $attn \n
                   Contact Time: $con_time \n
                   Message: $comments \n
                   From: $name \n
                   Phone: $phone \n
                   Additional Info : IP = $ip \n
                   Browser Info: $httpagent \n
                   Referral : $httpref \n
                   From the Rouse web site.\n
                   ";

   $myMail->Mailer = 'smtp';
   $myMail->Host = 'mail.rouse.ws';
   $myMail->Port = 2525; //Site Ground email suggest this //587; //465 Original author suggested last 2
   $myMail->SMTPSecure = 'tls';
   $myMail->SMTPAuth = true; // turn on SMTP authentication
   $myMail->Username = 'mailer+rouse.ws'; // SMTP username
   $myMail->Password = 'pr0gramm3r'; // SMTP password -- Don't know


   $myMail->Send();
   echo " Congratulations, '.$name.'. We've received your email. We'll be in touch as soon as we possibly can! ";

} # end if no error 
else {

   $response = ( isset ($error['name']))?''.$error['name'].' \n':null;
   $response .= ( isset ($error['email']))?''.$error['email'].' \n':null;
   $response .= ( isset ($error['comments']))?''.$error['comments'].'':null;

   echo $response;
} # end if there was an error sending 

?>

 

WBR

  • 9 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...