Log in

View Full Version : Double-check a contact form



katiebugla
10-02-2012, 02:57 PM
I borrowed this form from a previous website I "frankensteined" - my friend helped me with this script.... I was hoping to use it again for this website http://richieadams.com (click on contact)

Does all the documentation look correct, will this form work?


<div id="contactFormContainer" class="clearfix">
<form action="email.php" method="POST" class="form" id="contactForm">
<span class="hidden isSubmitted">Submitted</span>
<label for="name">Name</label>
<input type="text" id="name" name="name" class="validate[required,custom[onlyLetterSp],maxSize[30]] text-input" />
<label for="email">Email</label>
<input type="email" id="email" name="email" class="validate[required,custom[email]] text-input" />
<label for="subject">Subject</label>
<input type="text" id="subject" name="subject" class="validate[required,custom[onlyLetterSp],maxSize[40]] text-input" />
<label for="message">Messsage</label>
<textarea name=message id=message class="validate[required] text-input"></textarea><br />
<input type="submit" value="Submit" name="submit" class="submit">
<input type="reset" value="Clear" name="clear" class="submit">
</form>
</div>


<?php

require_once 'lib/swift_required.php';

// Set who is going to get the email
$to = 'info@rrc.la';

// Set the subject. This is being pulled from posted form
$subject = $_POST['subject'];
$from = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['message'];
$date = date("F j, Y, g:i a", strtotime('2 hours'));

$message = Swift_Message::newInstance()

->setSubject('RRC.LA Contact Form: ' . $subject)

//Set the From address with an associative array
->setFrom(array($from => $name))

//Set the To addresses with an associative array
->setTo(array($to))

//Give it a body
->setBody("Subject: $subject \n From: $name \n Message: $message \n\n timestamp: $date")

//And optionally an alternative body
->addPart("<h3>RRC.LA Contact Form</h3><b>Subject:</b> $subject <br /><br /> <b>From:</b> $name <br /><br /> <b>Message:</b> $message <br /><br /><br /><i>timestamp: $date", 'text/html')
;

$transport = Swift_MailTransport::newInstance();

$mailer = Swift_Mailer::newInstance($transport);

$result = $mailer->send($message);

$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'contact.html#submitted';
header("Location: http://$host$uri/$extra");

ajfmrf
10-02-2012, 07:01 PM
did you test it?

katiebugla
10-02-2012, 07:09 PM
I just tested it and am waiting for my boss to let me know if he got the test email or not... I have a white page after hitting submit. I thought there was something in the PHP to have it load the same page, but with "submitted" in the contact form box.

bernie1227
10-02-2012, 11:04 PM
It looks alright, when it is submitted, it should go to a page called email.php which might be blank. Only now thing, in add
Art, you forgot to end an <I> tag.

katiebugla
10-03-2012, 02:43 PM
Where is this <i> tag? I apologize for my ignorance. Also, it would seem that a) my boss did not receive the TEST email and b) I am not sure how to program the page to populate the way it did on the other site, see http://riverroadcreative.co/contact.html... I need it to work like that and I'm not sure what I am doing/doing wrong. Thank you.

bernie1227
10-04-2012, 12:18 AM
the <i> tag is here:


//And optionally an alternative body
->addPart("<h3>RRC.LA Contact Form</h3><b>Subject:</b> $subject <br /><br /> <b>From:</b> $name <br /><br /> <b>Message:</b> $message <br /><br /><br /><i>timestamp: $date", 'text/html')
;

another point, is that the whole code? Because there is no php ending (?>).

I would put in some trouble shooting code there, ie printing some variables and seeing if they come up, ie:


<?php

require_once 'lib/swift_required.php';

// Set who is going to get the email
$to = 'info@rrc.la';

// Set the subject. This is being pulled from posted form
$subject = $_POST['subject'];
$from = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['message'];
$date = date("F j, Y, g:i a", strtotime('2 hours'));


echo $subject; // troubleshooting code
echo $from;
echo $name;
echo $message;
echo $date;


$message = Swift_Message::newInstance()

->setSubject('RRC.LA Contact Form: ' . $subject)

//Set the From address with an associative array
->setFrom(array($from => $name))

//Set the To addresses with an associative array
->setTo(array($to))

//Give it a body
->setBody("Subject: $subject \n From: $name \n Message: $message \n\n timestamp: $date")

//And optionally an alternative body
->addPart("<h3>RRC.LA Contact Form</h3><b>Subject:</b> $subject <br /><br /> <b>From:</b> $name <br /><br /> <b>Message:</b> $message <br /><br /><br /><i>timestamp: $date", 'text/html')
;

$transport = Swift_MailTransport::newInstance();

$mailer = Swift_Mailer::newInstance($transport);

$result = $mailer->send($message);

$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'contact.html#submitted';
header("Location: http://$host$uri/$extra");
?>

if that echos the variables, then it must be a problem with the mailing system.

katiebugla
10-04-2012, 03:52 PM
Unfortunately, I don't really know PHP, so the lingo is over my head... I don't understand the suggestion or what it is would do. Can you dumb it down for me? I'm sorry.

katiebugla
10-04-2012, 04:16 PM
I think I am getting closer, see richieadams.com (http://richieadams.com) (click contact) - However, when I submit I get a white page.

katiebugla
10-04-2012, 05:12 PM
I'm now a little concerned that neither site is actually forwarding the contact form... I am so clueless at all of this. I really need help.

katiebugla
10-04-2012, 06:25 PM
Ok, so I am no trying another form that another friend recommended, but i sent and got the message 'Thank you for the message. We will contact you shortly.' Which is hopeful... but I keep checking my email... nothing is coming in. Thoughts?:

form class="form" action="contact-form.php" method="post">
<div class="move-over">
<h3>Name:</h3><input type="text" name="cf_name" value="" /><br />

<h3>Email Address:</h3><input type="text" name="cf_email" value="" /><br />
</div>
<div class="move-over">
<h3>Message:</h3><textarea class="bigger" name="cf_message" value="" ></textarea><br />
<br />
<input type="submit" value="Send" />
<input type="reset" value="Clear" />
</div>
</form>


<?php
$field_name = $_POST['cf_name'];
$field_phone = $_POST['cf_phone'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'katie@rrc.la';
$subject = 'Message from RA website';

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to katie@rrc.la');
window.location = 'contact.html';
</script>
<?php
}
?>

bernie1227
10-04-2012, 10:32 PM
You've got three php tags and they're ending in very odd places, try this:


<?php
$field_name = $_POST['cf_name'];
$field_phone = $_POST['cf_phone'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'katie@rrc.la';
$subject = 'Message from RA website';

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);
?>
<script type="text/javascript">
if (<?php $mail_status ?>) {
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact.html';
}
else {
alert('Message failed. Please, send an email to katie@rrc.la');
window.location = 'contact.html';
}
</script>