form - attachments based on checkboc

Hi,

I am a complete newbie but I have a PHP script that delivers an email to me based on a completed form. This works fine but I now need to do something slightly different.

Part of the form is now the selection of various checkbox’s and I would like to send an email to the person that is completing the form that includes a PDF attachment for each of the checkbox’s they have selected.

Any help would be much appreciated.

Michael
[php]<?php

if(isset($_POST[‘email’])) {

$email_to = "[email protected]";

$email_subject = "Get Files";

 

 

function died($error) {

    echo "We are very sorry, but there were error(s) found with the form you submitted. ";

    echo "These errors appear below.<br /><br />";

    echo $error."<br /><br />";

    echo "Please go back and fix these errors.<br /><br />";

    die();

}

 

// validation expected data exists

if(!isset($_POST['first_name']) ||

    !isset($_POST['last_name']) ||

    !isset($_POST['email'])) {

    died('We are sorry, but there appears to be a problem with the form you submitted.');       

}

 

$first_name = $_POST['first_name']; // required

$last_name = $_POST['last_name']; // required

$email_from = $_POST['email']; // required

$telephone = $_POST['telephone']; // not required

$company = $_POST['company']; // not required

$postcode = $_POST['postcode']; // not required

$comment = $_POST['comment']; // not required

$prod_check1 = $_POST['check1']; // not required

$prod_check2 = $_POST['check2']; // not required

$prod_check3 = $_POST['check3']; // not required

$prod_check4 = $_POST['check4']; // not required

$prod_check5 = $_POST['check5']; // not required

$prod_check6 = $_POST['check6']; // not required



 

$error_message = "";

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email_from)) {

$error_message .= 'The Email Address you entered does not appear to be valid.<br />';

}

$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$first_name)) {

$error_message .= 'The First Name you entered does not appear to be valid.<br />';

}

if(!preg_match($string_exp,$last_name)) {

$error_message .= 'The Last Name you entered does not appear to be valid.<br />';

}

if(strlen($error_message) > 0) {

died($error_message);

}

$email_message = "Form details below.\n\n";

 

function clean_string($string) {

  $bad = array("content-type","bcc:","to:","cc:","href");

  return str_replace($bad,"",$string);

}

 

$email_message .= "First Name: ".clean_string($first_name)."\n";

$email_message .= "Last Name: ".clean_string($last_name)."\n";

$email_message .= "Email: ".clean_string($email_from)."\n";

$email_message .= "Telephone: ".clean_string($telephone)."\n";

$email_message .= "Company: ".clean_string($company)."\n";

$email_message .= "Postcode: ".clean_string($postcode)."\n";

$email_message .= "Comment: ".clean_string($comment)."\n";

$email_message .= "Prod1: ".clean_string($prod_check1)."\n";

$email_message .= "Prod2: ".clean_string($prod_check2)."\n";

$email_message .= "Prod3: ".clean_string($prod_check3)."\n";

$email_message .= "Prod4: ".clean_string($prod_check4)."\n";

$email_message .= "Prod5: ".clean_string($prod_check5)."\n";

$email_message .= "Prod6: ".clean_string($prod_check6)."\n";

// create email headers

$headers = 'From: '.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

‘X-Mailer: PHP/’ . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);
header(“Location: thankyou.html”);

?>

<?php } ?>[/php]

Learn how to program in PHP first. While I realize this is a novel idea now, the fact that you don’t know how to approach this other than to throw code you found in a forum asking for help speaks volumes.

Figure out how to:
create a decision structure.
attach files to emails.
Properly return an error message.

Those few things are a big deal to accomplish your task.

Thanks for the pointers I will go and do exactly that.

Sponsor our Newsletter | Privacy Policy | Terms of Service