Hi
I am using the following php script to collect form data and send it in an email. Can anybody please provide the php code to attach multiple attachments in the email that I am sending. I have googled but haven't found a good answer yet. Any help would be greatly appreciated.
<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST'){
header('Refresh: 0; URL=/index.html');
exit;
}
function Valid_Input($data){
list($data) = preg_split('/\r|\n|%0A|%0D|0x0A|0x0D/i',ltrim($data));
return $data;
}
function Valid_Email($data){
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
if (preg_match($pattern,$data)){
return $data;
}
else{
return $GLOBALS['mailto'];
}
}
$message = "";
$name = Valid_Input($_POST['name']);
$emailaddr1 = Valid_Email($_POST['emailaddr1']);
$emailaddr2 = Valid_Email($_POST['emailaddr2']);
$phonenumber = Valid_Input($_POST['phonenumber']);
$targetinmiles = Valid_Input($_POST['targetinmiles']);
$prefinale = Valid_Input($_POST['prefinale']);
$grandfinale = Valid_Input($_POST['grandfinale']);
foreach ($_POST as $key => $value){
if (!is_array($value)){
$message .= "\n".$key." : ".$value;
}
else{
foreach ($_POST[$key] as $itemvalue){
$message .= "\n".$key." : ".$itemvalue;
}
}
}
$emailfrom = "chalisa4harefield@gmail.com";
$mailto = $emailaddr1;
$subject = "Hanuman Chalisa for Harefield 2021";
$organisers = "Hanuman Chalisa 4 Harefield";
$header = "From: ".$organisers." <".$emailfrom.">\n";
$header .= "Reply-To: ".$emailfrom."\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/plain; charset=utf-8\n";
$header .= "Content-Transfer-Encoding: 8bit\n";
$header .= "X-Mailer: PHP v".phpversion();
mail($mailto, $subject, stripslashes($message), $header) or exit('Fatal Mail Error!');
?>
The project can be downloaded from here if anybody wants to have a look at the form.
https://1drv.ms/u/s!Ajp8jGjiAz6Shqt3BxC ... g?e=xDJaQl
php script to send form fields in an email with multiple attachments
Forum rules
PLEASE READ THE FORUM RULES BEFORE YOU POST:
viewtopic.php?f=12&t=1901
MUST READ:
http://www.wysiwygwebbuilder.com/forms.html
http://www.wysiwygwebbuilder.com/form_wizard.html
Frequently Asked Questions about Forms
PLEASE READ THE FORUM RULES BEFORE YOU POST:
viewtopic.php?f=12&t=1901
MUST READ:
http://www.wysiwygwebbuilder.com/forms.html
http://www.wysiwygwebbuilder.com/form_wizard.html
Frequently Asked Questions about Forms
Re: php script to send form fields in an email with multiple attachments
The built-in form processor supports multiple attachments when mail engine is set to phpmailer.
Re: php script to send form fields in an email with multiple attachments
OK thanks, I will give it a try but I have never used the built-in form processor so will have to learn it all. Any idea where I can get all the information from or an exaple?
I also want to write the form data to an excel file. Will this be possible?
I also want to write the form data to an excel file. Will this be possible?
Re: php script to send form fields in an email with multiple attachments
I cannot help you with custom coding, but this may be helpful:
https://icodemag.com/how-to-send-an-ema ... and-gmail/
https://icodemag.com/how-to-send-an-ema ... and-gmail/
Re: php script to send form fields in an email with multiple attachments
maybe have a look at my dynamic attachments script, you can add it to any WB forms you already have in place. There is also a demo of it as well.
Check it out here
https://shop.grahamscomputers.net/webshop.html
Graham
Check it out here
https://shop.grahamscomputers.net/webshop.html
Graham