Jump to content

phpmailer contact form help for complete novice


basquen

Recommended Posts

Hi,

I've spent most of the afternoon battling with a phpmailer script to get it working with gmail smtp authentification. I've used  a modified class.phpmailer.php and class.smtp.php  scripts to handle the gmail ssl authentification & my contact form now works fine. (Submit and received).

 

However I'm stuck on a ridiculously simple problem.

The form is called to display in a static html page as follows:

 

 <?
include("form.php");
?>

 

form.php


<link href="css/master.css" rel="stylesheet" type="text/css" />
<form action="lib/phpmailer/ozcontact.php" method="post" enctype="multipart/form-data">
    <table width="450">
        <tr>
            <td class="label">Name *</td>
            <td><input type="text" name="sender_name" value="" /></td>
        </tr>
        <tr>
            <td class="label">E-mail address *</td>
            <td><input type="text" name="sender_email" value="" /></td>
        </tr>
        <tr>
            <td class="label">Subject *</td>
            <td><input type="text" name="subject" value="" /></td>
        </tr>
        <tr>
          <td>Message *</td>
          <td><textarea name="message" rows="10" cols="30"></textarea></td>
        </tr>
        <tr>
            <td colspan="2"><br /></td>
        </tr>
        <tr>
            <td colspan="2" align="right"><input name="submit" type="submit" class="buttonSubmit" value="Submit" /><input type="reset" class="buttonSubmitblue" value="Reset"></td>
        </tr>
  </table>
</form>

 

on submit, the form is handled by ozcontact.php as follows:

<?php

require_once 'class.phpmailer.php';
//get contact form details
$name = $_POST['sender_name'];
$email = $_POST['sender_email'];
$subject = $_POST['subject'];
$comments = $_POST['message'];

$html_font = "verdana";
$html_font_size = "10pt";
$alink_color = "#11116E";
$vlink_color = "#11116E";
$hlink_color = "#000000";

$response="<html>\n<head>\n<style>\nA:link {text-decoration: none; color: $alink_color;}\nA:visited {text-decoration: none; color: $vlink_color;}\nA:hover {font-style: italic; color: $hlink_color; text-decoration: underline;}\nBODY{font-family: $html_font; font-size: $html_font_size;}TD {font-family: $html_font; color: #000000; font-size: $html_font_size;}\n</style>\n</head>\n<body>\n\n<table border=\"0\" cellpadding=\"6\" cellspacing=\"0\" width=\"100%\">\n<tr>\n <td nowrap width=\"1%\">\n<b>Submitted</b>\n</td>\n<td width=\"99%\">Date: " . date("d F, Y ") ."\n</td>\n</tr>\n<tr>\n<td nowrap width=\"1%\">\n<b>From</b></td>\n<td width=\"99%\"> $name\n- <A HREF=\"mailto:$email\">$email</A></td>\n</tr>\n<tr>\n<td nowrap width=\"1%\">\n<b>Subject</b></td>
    \n<td width=\"99%\"> $subject\n</td>
    \n</tr>\n<tr>\n<td nowrap width=\"1%\" valign=\"top\">\n<b>Message</b></td>\n<td width=\"99%\">".nl2br($comments)."</td>\n</tr>\n\n</table>
<br>\n<br>\n<div align=\"right\"><i>My company <A HREF=\"http://www.myweb.com\">my url</A></i></div></body></html>
"
;


$mail = new PHPMailer ();

$mail -> From = $name;
$mail -> FromName = $email;
$mail -> AddAddress ("xxx@gmail.com");
$mail -> Subject = "Website Enquiry";
$mail -> Body = $response;
$mail -> IsHTML (true);

$mail->IsSMTP();
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'xxx@gmail.com';
$mail->Password = 'xxxxxx';

if(!$mail->Send()) {
        echo 'Error: ' . $mail->ErrorInfo;
}
else {
{       echo 'Thanks for contacting us - we will get back to you very soon!';
}
}
?>

 

 

On submit I need to refresh the form and display a thank-you message within the static html page. As it stands the whole page is refreshed. Once this is solved I need to add simple validation to the form....

 

Any help would be gratefully received - I'm tearing my hair out now!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.