Jump to content

Help with email form, please


SteveH

Recommended Posts

Hello

 

I have an email script which works fine with an online form.

 

This is the original form:

 

<form action='#' style='display:none'>
<label for='contact-name'>*Name:</label>
<input type='text' id='contact-name' class='contact-input' name='name' tabindex='1001' />

<label for='contact-email'>*Email:</label>
<input type='text' id='contact-email' class='contact-input' name='email' tabindex='1002' />";

if ($extra["form_subject"]) {
	$output .= "
<label for='contact-subject'>Subject:</label>
<input type='text' id='contact-subject' class='contact-input' name='subject' value='' tabindex='1003' />";
}

$output .= "
<label for='contact-message'>*Message:</label>
<textarea id='contact-message' class='contact-input' name='message' cols='40' rows='4' tabindex='1004'></textarea>
		<br/>";

if ($extra["form_cc"]) {
	$output .= "
<label> </label>
<input type='checkbox' id='contact-cc' name='cc' value='1' tabindex='1005' /> <span class='contact-cc'>Send me a copy</span>
		<br/>";
}

$output .= "

<label> </label>
<button type='submit' class='contact-send contact-button' tabindex='1006'>Send</button>
<button type='submit' class='contact-cancel contact-button simplemodal-close' tabindex='1007'>Cancel</button>
<br/>
<input type='hidden' name='token' value='" . smcf_token($to) . "'/>
</form>

 

I have tried to add the following (after the message field), but get an error message:

 

if ($extra["form_attachment"]) {
	$output .= "
      <label for='contact-attachment'>*Name:</label>
<input type='text' id='contact-attachment' class='contact-input'          name='name' tabindex='1001' />

<label for='contact-email'>Attachment:</label>
<input type='text' id='contact-attachment' class='contact-input' name='attachment' tabindex='1002' />";

 

Any help would be appreciated.

 

Thanks.

 

Steve

Link to comment
https://forums.phpfreaks.com/topic/180293-help-with-email-form-please/
Share on other sites

Hi Steve,

 

You're not closing the above code with a closing } bracket.

 

Change your code to read:

 

if ($extra["form_attachment"]) {
	$output .= "
      <label for='contact-attachment'>*Name:</label>
<input type='text' id='contact-attachment' class='contact-input' name='name' tabindex='1001' />

<label for='contact-email'>Attachment:</label>
<input type='text' id='contact-attachment' class='contact-input' name='attachment' tabindex='1002' />";
}

 

Hope this helps.

Hello Bricktop

 

Thanks for your post.

 

That's got rid of the error, cheers.

 

I have also added the attachment here:

 

// Include extra form fields and/or submitter data?
// false = do not include
$extra = array(
"form_subject"	=> true,
"form_cc"		=> true,
[b]"form_attachment" => true,[/b]"ip"		=> true,
"user_agent"	=> true
);

 

and wondered if I also needed to add attachment in the script below:

 

else if ($action == "send") {
// Send the email
$name = isset($_POST["name"]) ? $_POST["name"] : "";
$email = isset($_POST["email"]) ? $_POST["email"] : "";
$subject = isset($_POST["subject"]) ? $_POST["subject"] : $subject;
$message = isset($_POST["message"]) ? $_POST["message"] : "";
$cc = isset($_POST["cc"]) ? $_POST["cc"] : "";
$token = isset($_POST["token"]) ? $_POST["token"] : "";

// make sure the token matches
if ($token === smcf_token($to)) {
smcf_send($name, $email, $subject, $message, $cc);
echo "Your message was successfully sent.";
}
else {
	echo "Unfortunately, your message could not be verified.";
}
}

 

Thanks again for any advice.

 

Steve

Hi Steve,

 

Give the following a try:

 

else if ($action == "send") {
// Send the email
$name = isset($_POST["name"]) ? $_POST["name"] : "";
$email = isset($_POST["email"]) ? $_POST["email"] : "";
$subject = isset($_POST["subject"]) ? $_POST["subject"] : $subject;
$message = isset($_POST["message"]) ? $_POST["message"] : "";
$cc = isset($_POST["cc"]) ? $_POST["cc"] : "";
$token = isset($_POST["token"]) ? $_POST["token"] : "";
//Grab the two new $_POST values and assign them to variables
$attachmentname = isset($_POST["name"]) ? $_POST["name"] : "";
$attachment = isset($_POST["attachment"]) ? $_POST["attachment"] : "";


//Create a new $message variable, combining $message, $attachmentname and $attachment 

$message = "Message:  $message\n\nAttachment Name:  $attachmentname\n\nAttachment:  $attachment\n\n"



// make sure the token matches
if ($token === smcf_token($to)) {
smcf_send($name, $email, $subject, $message, $cc);
echo "Your message was successfully sent.";
}
else {
	echo "Unfortunately, your message could not be verified.";
}
}

 

Hopefully the above should do what you want, it will send the contents of the attachment name and attachment fields in the main email body.

 

Hope this helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.