Jump to content

Help with form


justspiffy

Recommended Posts

Hey everyone,

 

I purchased a template to make a website with and need a little bit of help with altering the contact form. The form works fine, when someone fills out the form online and the email comes to me, the reply to email address is the one they inputted into the form. However, when I click "reply" in the email, it changes to my email address(the $fromEmail which I was trying to override)

 

Here is the send.php

 

<?php
$ajax = (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
$ajax = true;
//we do not allow direct script access
if (!$ajax) {
	//redirect to contact form
	echo "Please enable Javascript";
	exit;
}
require_once "config.php";

//we set up subject
$mail->Subject = isset($_REQUEST['email_subject']) ? $_REQUEST['email_subject'] : "Message from site";

//let's validate and return errors if required
$data = $mail->validateDynamic(array('required_error' => $requiredMessage, 'email_error' => $invalidEmail), $_REQUEST);

//let's make sure we have valid data
//if (!$data['errors'] && (!isset($_REQUEST['js']) || $_REQUEST['js'] != 1)) {
//$data['errors']['global'] = 'Javascript is required. Please try again';
//}

if ($data['errors']) {
	echo json_encode(array('errors' => $data['errors']));
	exit;
}
 
//force to overwrite email address
$mail->SetFrom($data['fields']['Email'], $data['fields']['Name'].' '.$data['fields']['Surname']);

$html = '<body style="margin: 10px;">
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
  <h2>' . $mail->Subject . '</h2>
';

foreach ($data['fields'] as $label => $val) {
	$html .= '<p>' . $label . ': ' . $val . '</p>';
}

$html .= '</div></body>';

$mail->setup($html, $_REQUEST, array());

$result = array('success' => 1);
if (!$mail->Send()) {
	$result['success'] = 0;
}

echo json_encode($result);
exit;

config.php

<?php
/**
 * Setup mail server config
 */
ini_set('display_errors', 0);

//where we would like to send email
$recipientEmail = 'contact@justspiffy.ca';
$recipientName = 'The Touchmark';

//Address which will be visible in "From" field
$fromEmail = 'contact@justspiffy.ca';
$fromName = 'Site Admnistrator';

//Validation error messages
$requiredMessage = 'Field is required';
$invalidEmail = 'Invalid email';

/**
 * Advanced configuration - no need to modify
 */

require_once(dirname(__FILE__) . '/vendor/ctPHPMailer.php');
$mail = new ctPHPMailer();

//set your email address
$mail->AddAddress($recipientEmail, $recipientName);
$mail->SetFrom($fromEmail, $fromName);

$debug = false; //if problems occur, set to true to view debug messages

I do not know much about php so I am not sure what to do to make it stay as the users email address when they click "reply" on the email. Any ideas would be great.

 

 

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.