I hope you will help me with my question, because i really need it for my site.
How do i add the possibility to attach a file to a online emailer I've written in PHP? :)
Here is the code that i would like to add it to:
<?php
session_start();
if( isset($_POST['submit']))
{
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) )
{
$to=$_POST["to"];
$from=$_POST["from"];
$name=$_POST["name"];
$subject=$_POST["subject"];
$message=$_POST["message"];
$message=$message."\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
$head="From: ".$from."\r\n".'Reply-To: '.$From."\r\n";
$her=$head.' < '.$from.' >';
$techomag=mail($to, $subject, $message, $her);
echo "Your Message Has been send successfully...:)..";
unset($_SESSION['security_code']);
echo( 'Click here to send another email' );
}
else
{
echo 'Sorry, you have provided an invalid captcha security code :(...';
echo( 'Click here to Go back and try once more' );
}
}
else
{
?>
<?php
?>
<div style="height:10px; clear:both"></div>
<form action="index.php" method="post">
<table border="1"><tbody>
<tr><td>To Email :</td><td><input name="to" type="text" /></td></tr>
<tr><td>From Email :</td><td><input name="from" type="text" /></td></tr>
<tr><td>From Name :</td><td><input name="name" type="text" /></td></tr>
<tr><td>Subject :</td><td><input name="subject" type="text" /></td></tr>
<tr><td>Message :</td><td><textarea cols="30" rows="10" name="message"></textarea></td></tr>
<tr><td><img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br />
<label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" />
<input type="submit" name="submit" value="Send Email!" /></td></tr>
</tbody></table>
</form>
<?php
}
?>
Well for complex emailing with PHP checkout the PHPMailer class.
It is much easier to send complex emails (e.g. with attachment) with the functions in PHPMailer.
<?php
$filename = "form.txt"; //attach filename
$to = "abc#mail.ru"; //To
$from = "def#gmail.com"; //From
$subject = "Test"; //Subj
$message = "Текстовое сообщение"; //Message
$boundary = "---"; //Delimitter
/* Headers */
$headers = "From: $from\nReply-To: $from\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
$body = "--$boundary\n";
/* Text message */
$body .= "Content-type: text/html; charset='utf-8'\n";
$body .= "Content-Transfer-Encoding: quoted-printablenn";
$body .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode($filename)."?=\n\n";
$body .= $message."\n";
$body .= "--$boundary\n";
$file = fopen($filename, "r"); //Открываем файл
$text = fread($file, filesize($filename)); //Считываем весь файл
fclose($file); //Закрываем файл
/* ADD attach */
$body .= "Content-Type: application/octet-stream; name==?utf-8?B?".base64_encode($filename)."?=\n";
$body .= "Content-Transfer-Encoding: base64\n";
$body .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode($filename)."?=\n\n";
$body .= chunk_split(base64_encode($text))."\n";
$body .= "--".$boundary ."--\n";
mail($to, $subject, $body, $headers); //SEND
?>
Related
I have a simple form which sending an email with some fields and also it saves the fields in .csv file.
Here is my code (HTML, jQuery, PHP)
The Form:
<form id="request-size">
<input name="email" id="email" type="email" class="cmesgmail" placeholder="email">
<input type="hidden" name="size" id="size" value="52">
<input type="hidden" name="sku" id="sku" value="315">
<input type="hidden" name="pridpr" id="pridpr" value="849">
<input class="request-size-btn btn" value="SEND">
</form>
The jQuery:
jQuery('.request-size-btn').live('click', function() {
jQuery.ajax({
type: "POST",
url: "https://example.com/sendmail.php",
data: jQuery('form#request-size').serializeArray(),
success: function( data ) {
jQuery('.cmesg').empty();
jQuery('.cmesg').append(data);
}
});
});
});
The PHP Sendmail:
$EmailFrom = $_REQUEST['email'];
$SKU = $_REQUEST['sku'];
$SIZE = $_REQUEST['size'];
$ID = $_REQUEST['pridpr'];
$EmailTo = "info#example.com";
$Subject = "Contact for Size";
$DATENOW = date('d/m/Y h:i:s a', time());
$Body = "";
$Body .= "<b>Email:</b> ";
$Body .= $EmailFrom . "\r\n";
$Body .= "<br>";
$Body .= "<b>Product SKU:</b> ";
$Body .= $SKU . "\n";
$Body .= "<br>";
$Body .= "<b>Product ID:</b> ";
$Body .= $ID . "\n";
$Body .= "<br>";
$Body .= "<b>Product Size:</b> ";
$Body .= $SIZE;
$Body .= "<br>";
$Body .= "<b>Date:</b> ";
$Body .= $DATENOW;
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\n";
$headers .= "From: ". $EmailFrom ."" . "\n";
$success = mail($EmailTo, $Subject, $Body, $headers);
if ($success){
echo '<div class="alert alert-success">Done!</div>';
$file = fopen('request-size.csv', 'a');
$data = array(
array($EmailFrom, $SKU, $ID, $SIZE, $DATENOW)
);
foreach ($data as $row)
{
fputcsv($file, $row);
}
fclose($file);
}
else{
echo '<div class="alert alert-danger">Error!</div>';
}
I've got all the fields in my csv file and email, except the "email" field. It's always empty. I have also try to change the name of email field (email to emailreq) on both sides (html, php), but didn't work.
Any suggestions? Thank you!
If updating jQuery is an option for you, do that. Version 1.6.2 and up should be working (possibly also before, but i'm not sure).
Otherwise change the
<input name="email" id="email" type="email" class="cmesgmail" placeholder="email">
to
<input name="email" id="email" type="text" class="cmesgmail" placeholder="email">
Older versions of jQuery did not include support for the HTML5 input types.
i have this script for sending mails from a emails.txt list and is working fine but is there a way to delay the sending of emails from the list?
Any help is appreciated,thanks!
This is the Php sender script:
if($_POST)
{
$recipient_email = '';
$name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$from_email = filter_var($_POST["sender_email"], FILTER_SANITIZE_STRING);
$bcc = filter_var($_POST["bcc"], FILTER_SANITIZE_STRING);
$reply_to_email = filter_var($_POST["email"], FILTER_SANITIZE_STRING);
$subject = filter_var($_POST["subject"], FILTER_SANITIZE_STRING);
$message = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
$mesaj = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
//Get uploaded file data
$file_tmp_name = $_FILES['my_file']['tmp_name'];
$file_name = $_FILES['my_file']['name'];
$file_size = $_FILES['my_file']['size'];
$file_type = $_FILES['my_file']['type'];
$file_error = $_FILES['my_file']['error'];
$lista = $_FILES['lista']['tmp_name'];
if($file_error > 0)
{
die('Upload error or No files uploaded');
}
$handle = fopen($file_tmp_name,'rb');
// Now read the file content into a variable
$content = fread($file,filesize($file_tmp_name));
// close the file
fclose($handle);
// Now we need to encode it and split it into acceptable length lines
$encoded_content = chunk_split(base64_encode(file_get_contents($file_tmp_name)));
$uid = md5(date('r', time()));
//header
$headers = "From: ".$name." <".$from_email.">\r\n";
$headers .= "Bcc: $bcc\r\n";
$headers .= "Reply-To: ".$reply_to_email."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$uid."\"\r\n\r\n";
$message = "--PHP-mixed-$uid\r\n"."Content-Type: multipart/alternative; boundary=\"PHP-alt-$uid\"\r\n\r\n";
$message .= "--PHP-alt-$uid\r\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";
//Insert the html message.
$message .= $mesaj;
$message .="\r\n\r\n--PHP-alt-$uid--\r\n\r\n";
//include attachment
$message .= "--PHP-mixed-$uid\r\n"."Content-Type: $file_type; name=\"$file_name\"\r\n"."Content-Transfer-Encoding: base64\r\n"."Content-Disposition: attachment\r\n\r\n";
$message .= $encoded_content;
$message .="Content-Transfer-Encoding: base64\r\n";
$message .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$message .= "/r/n--PHP-mixed-$uid--";
$list = fopen($lista, "r");
if ($list) {
while (($line = fgets($list)) !== false) {
if (!mail($line, $subject, $message, $headers))
{
echo "Eroare! Nu am putut trimite mailurile.";
}
else
{
echo "Mailurile au fost trimise!";
}
}
fclose($list);
}
}
Html form fields:
<form enctype="multipart/form-data" method="POST" action="">
<label>Name <input type="text" name="sender_name" /> </label>
</br><label>Mail <input type="email" name="sender_email" /> </label>
<label>Bcc <input type="text" name="bcc" /> </label>
</br><label>Subject <input type="text" name="subject" /> </label>
</br> <label>Message <textarea name="message"></textarea> </label>
</br><label>attachment <input type="file" name="my_file" /></label>
</br><label>Mail list <input type="file" name="lista" /></label>
</br> <label><input type="submit" name="button" value="Fire :)" /></label>
</form>
you can use the sleep() command to pause it
while (($line = fgets($list)) !== false) {
if (!mail($line, $subject, $message, $headers))
{
echo "Eroare! Nu am putut trimite mailurile.";
}
else
{
echo "Mailurile au fost trimise!";
}
sleep(3)
}
for example
I am developing website in html. In Careers.html page i am having Apply button. On clicking that apply button it will send the mail using php file. On suceess event i need to set the alert or to show the div on the same Careers.html page.
Careers.html
<form method="post" action="Applyresume.php" enctype="multipart/form-data">
<tr>
<td>First Name </td>
<td><input type="TextBox" name="First_Name" class="applytext" required></td>
</tr>
<tr>
<td>Last Name </td>
<td><input type="TextBox" name="Last_Name" class="applytext" required></td>
</tr>
<tr>
<td>E-mail </td>
<td><input type="TextBox" name="email" class="applytext" required></td>
</tr>
<tr>
<td>Phone </td>
<td><input type="TextBox" name="Phone_No" class="applytext" required></td>
</tr>
<tr>
<td>Attachment </td>
<td><input type="file" name="attachment" maxlength="50" allow="text/*" class="applytext" required></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="button" class="send-resume" value="SEND" style="margin-left:24%;">
<input type="reset" value="RESET" style="margin-left:8%"></td>
</tr>
</form>
Applyresume.php
<?php
if($_POST && isset($_FILES['attachment']))
{
$name= $_POST['First_Name'];
$lname= $_POST['Last_Name'];
$email= $_POST['email'];
$phonenum = $_POST['Phone_No'];
$from_email = $_POST['email']; //sender email
$recipient_email = 'nisha#acute.company'; //recipient email
$subject = 'Test Email '; //subject of email
$message = 'Resume attached below.'; //message body
$emailbod = "$name
$lname
$email
$phonenum";
//get file details we need
$file_tmp_name = $_FILES['attachment']['tmp_name'];
$file_name = $_FILES['attachment']['name'];
$file_size = $_FILES['attachment']['size'];
$file_type = $_FILES['attachment']['type'];
$file_error = $_FILES['attachment']['error'];
$user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
if($file_error>0)
{
die('upload error');
}
//read from the uploaded file & base64_encode content for the mail
$handle = fopen($file_tmp_name, "r");
$content = fread($handle, $file_size);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
$boundary = md5("sanwebe");
//header
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "Reply-To: ".$user_email."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
//plain text
$body = "--$boundary\r\n";
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode($emailbod));
//attachment
$body .= "--$boundary\r\n";
$body .="Content-Type: $file_type; name=\"$file_name\"\r\n";
$body .="Content-Disposition: attachment; filename=\"$file_name\"\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$body .= $encoded_content;
$sentMail = #mail($recipient_email, $subject, $body, $headers);
if($sentMail) //output success or failure messages
{
echo '<script type="text/javascript">alert("Thanks for your interest. Your Resume has been sent to HR#prominData.com");window.location.assign("Careers.html");</script>';
}else
{
echo"<script>alert('Could not send mail! Please check your PHP mail configuration.')</script>";
}
}
?>
My problem is I need to set the success alert in the same html page.
But here my success alert is opening in PHP page.
How to add this php code in same html page?
To view the message or alert on the same page, you can just copy your php code in the same HTML page. Do it as below
your_html.php
<form method="post" action="" enctype="multipart/form-data">
<tr>
<td>First Name </td>
<td><input type="TextBox" name="First_Name" class="applytext" required></td>
</tr>
<tr>
<td>Last Name </td>
<td><input type="TextBox" name="Last_Name" class="applytext" required></td>
</tr>
<tr>
<td>E-mail </td>
<td><input type="TextBox" name="email" class="applytext" required></td>
</tr>
<tr>
<td>Phone </td>
<td><input type="TextBox" name="Phone_No" class="applytext" required></td>
</tr>
<tr>
<td>Attachment </td>
<td><input type="file" name="attachment" maxlength="50" allow="text/*" class="applytext" required></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="button" class="send-resume" value="SEND" style="margin-left:24%;">
<input type="reset" value="RESET" style="margin-left:8%"></td>
</tr>
</form>
<?php
if($_POST && isset($_FILES['attachment']))
{
$name= $_POST['First_Name'];
$lname= $_POST['Last_Name'];
$email= $_POST['email'];
$phonenum = $_POST['Phone_No'];
$from_email = $_POST['email']; //sender email
$recipient_email = 'nisha#acute.company'; //recipient email
$subject = 'Test Email '; //subject of email
$message = 'Resume attached below.'; //message body
$emailbod = "$name
$lname
$email
$phonenum";
//get file details we need
$file_tmp_name = $_FILES['attachment']['tmp_name'];
$file_name = $_FILES['attachment']['name'];
$file_size = $_FILES['attachment']['size'];
$file_type = $_FILES['attachment']['type'];
$file_error = $_FILES['attachment']['error'];
$user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
if($file_error>0)
{
die('upload error');
}
//read from the uploaded file & base64_encode content for the mail
$handle = fopen($file_tmp_name, "r");
$content = fread($handle, $file_size);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
$boundary = md5("sanwebe");
//header
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "Reply-To: ".$user_email."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
//plain text
$body = "--$boundary\r\n";
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode($emailbod));
//attachment
$body .= "--$boundary\r\n";
$body .="Content-Type: $file_type; name=\"$file_name\"\r\n";
$body .="Content-Disposition: attachment; filename=\"$file_name\"\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$body .= $encoded_content;
$sentMail = #mail($recipient_email, $subject, $body, $headers);
if($sentMail) //output success or failure messages
{
echo '<script type="text/javascript">alert("Thanks for your interest. Your Resume has been sent to HR#prominData.com");window.location.assign("Careers.html");</script>';
}else
{
echo"<script>alert('Could not send mail! Please check your PHP mail configuration.')</script>";
}
}
?>
Dont forget to remove the action attribute of <form>. Also the extension of your HTML page should be changed to php.
set a condition on success
create a session
$_SESSION['action] = "Your Massage";
and when page refresh.
there would be a place where you want to echo that massage.
I have a form. With the following:
HTML:
<form name="feedback_form" method="post" enctype="multipart/form-data" action="" class="feedback_form">
<input type="text" name="field-name" value="İsim" title="İsim" class="field-name form_field">
<input type="text" name="field-email" value="Email" title="Email" class="field-email form_field">
<input type="text" name="field-subject" value="Başlık" title="Başlık" class="field-subject form_field">
<textarea name="field-message" cols="45" rows="5" title="Mesajınız..." class="field-message form_field">Mesajınız...</textarea>
<label for='uploaded_file'>Fotoğrafınızı Yükleyin:</label>
<input type="file" name="field-file" value="File">
<br>
<input type="reset" name="reset" id="reset2" value="Temizle" class="feedback_reset">
<input type="button" name="submit" class="feedback_go" id="submit2" value="Gönder">
</form>
PHP:
<?php
header('Content-Type: text/html; charset=utf-8');
function sendFeedback($feedback_email, $feedback_msg, $feedback_name, $feedback_subject, $feedback_file) {
/* EDIT THIS */
$admin_email = "mymail#gmail.com";
if ($feedback_subject == "Subject" || empty($feedback_subject) ) {
$subj = "Email from your site";
} else {
$subj = $feedback_subject;
}
/* //EDIT THIS */
$message = "
<html>
<head>
<title>Websitenizin emaili</title>
</head>
<body>
<p><a href='mailto:".$feedback_email."'>".$feedback_name."</a> send this message:</p>
<p>".$feedback_msg."</p>
<p>".$subject."</p>
</body>
</html>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
if ($feedback_name!=="Name" && $feedback_email!=="Email" && !empty($feedback_email) && !empty($feedback_msg) && !empty($feedback_name) ) {
if ($feedback_email == "mail_error") {
echo "<span class='ajaxok'>Geçersiz email adresi.</span>";
} else {
mail($admin_email, $subj, $message, $headers);
echo "<span class='ajaxok'>Teşekkürler. Mesajınız gönderilmiştir.</span>";
}
} else {
echo "<span class='ajaxalert'>Lütfen zorunlu alanları doldurunuz.</span>";
}
}
sendFeedback($_POST['email'], $_POST['message'], $_POST['name'], $_POST['subject'], $_FILES['file']);
?>
When send a message on this form, send email, working. But only subject, message, name and email. I want add image upload in this php code. But i don't know how can i do it? Please help me.
Look here: http://pastebin.com/nAErtHgt
I write this for Mail is sent without the attachment but it seems was not able to use it.
Add this function to your PHP file
function addattachment($file){
$fname = substr(strrchr($file, "/"), 1);
$data = file_get_contents($file);
$i = count($this->parts);
$content_id = "part$i." . sprintf("%09d", crc32($fname)) . strrchr($this->to_address, "#");
$this->parts[$i] = "Content-Type: ".mime_content_type($file)."; name=\"$fname\"\r\n" .
"Content-Transfer-Encoding: base64\r\n" .
"Content-ID: <$content_id>\r\n" .
"Content-Disposition: inline;\n" .
" filename=\"$fname\"\r\n" .
"\n" .
chunk_split( base64_encode($data), 68, "\n");
return $content_id;
}
and between $ message and $headers add
$message .= addattachment($feedback_file);
and should work.
Let me know if is working for you.
I don't recommend using PHP's mail function, use something like PHPMailer instead, it is a reasonable class for sending mails with multipart, attachments etc.
http://sourceforge.net/projects/phpmailer/ (Should be a lot of alternatives to this, but it works for me)
Then simply add the uploaded tmpfile as an attachment.
I have created a form that pulls a variable from a url using the following code:
<?php $id = $_GET['id']; echo $id; ?>
Using this is link as an example (http://www.mydomain.co.uk/customerform.php?id=12) it would display 12 on the webpage.
What I would like to know, is it possible to stop the web page from loading if there is no varible in the URL e.g ?id=12 ?
Either in php, javascript?
So If you visited the following link, the web page would display:
http://www.mydomain.co.uk/customerform.php?id=12
and if you visited this link (without the variable), the page would not display:
http://www.mydomain.co.uk/customerform.php
Thank you for any help.
Update below...
I have added Krishnanunni's code and it successfully prevents the web page from displaying if the is no vartiable in the url. But adding this code prevents the form submitting...
Is there a way of keeping the url variable when the form is submitted?
Can anyone help? Thanks
<body id="main_body" >
<div id="form_container">
<?
/* only load page is variable is presnt in the URL */
if (!isset($_GET['id']) || empty($_GET['id']))
{
die("Bad Request");
}
?>
<?
/* Mailer with Attachments */
$action = $_REQUEST['action'];
global $action;
function showForm() {
?>
<form id="contact" class="appnitro" name="idform" enctype="multipart/form-data" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="action" value="send" />
<input type="hidden" name="MAX_FILE_SIZE" value="10000000"/>
<input name="to_email" type="hidden" id="to_email" value="myemail#domain.co.uk"/>
<div>
<input id="invoice" name="invoice" class="element text medium" type="hidden" maxlength="255" value="<?php $id = $_GET['id']; echo $id; ?>"/>
</div>
<div>
<input id="subject" name="subject" class="element text medium" type="hidden" maxlength="255" value="Enquiry Form - (Invoice: <?php $id = $_GET['id']; echo $id; ?>)"/>
</div>
<label class="description" for="from_name">Name </label>
<div>
<input id="from_name" name="from_name" class="element text medium" type="text" maxlength="255" value=""/>
</div>
<label class="description" for="position">Position </label>
<div>
<input id="position" name="position" class="element text medium" type="text" maxlength="255" value=""/>
</div>
<label class="description" for="uemail"> Email </label>
<div>
<input id="email" name="email" class="element text medium" type="text" maxlength="255" value=""/>
</div>
<label class="description" for="phone"> Phone </label>
<div>
<input id="phone" name="phone" class="element text medium" type="text" maxlength="255" value=""/>
</div>
<input name="Reset" type="reset" class="contactform_small" value="Reset" />
<input name="Submit2" type="submit" class="contactform_small" id="Submit" value="Submit" />
</form>
<?
}
function sendMail() {
if (!isset ($_POST['to_email'])) { //Oops, forgot your email addy!
die ("<p>Oops! You forgot to fill out the email address! Click on the back arrow to go back</p>");
}
else {
$to_name = "MY BUSINESS";
$from_name = stripslashes($_POST['from_name']);
$subject = Trim(stripslashes($_POST['subject']));
$to_email = $_POST['to_email'];
$EmailFrom = Trim(stripslashes($_POST['email']));
// get posted data into local variables
$position = Trim(stripslashes($_POST['position']));
$position2 = Trim(stripslashes($_POST['position2']));
$phone = Trim(stripslashes($_POST['phone']));
$invoice = Trim(stripslashes($_POST['invoice']));
//Let's start our headers
$headers = "From: $EmailFrom<" . $_POST['email'] . ">\n";
$headers .= "Reply-To: <" . $_POST['email'] . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n";
$headers .= "X-Sender: $from_name<" . $_POST['email'] . ">\n";
$headers .= "X-Mailer: PHP4\n";
$headers .= "X-Priority: 3\n"; //1 = Urgent, 3 = Normal
$headers .= "Return-Path: <" . $_POST['email'] . ">\n";
$headers .= "This is a multi-part message in MIME format.\n";
$headers .= "------=MIME_BOUNDRY_main_message \n";
$headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n";
$message = "------=MIME_BOUNDRY_message_parts\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";
/* Add our message, in this case it's plain text. You could also add HTML by changing the Content-Type to text/html */
$message .= "Invoice: ";
$message .= $invoice;
$message .= "\n";
$message .= "\n";
$message .= "My Business Enquiry Form";
$message .= "\n";
$message .= "\n";
$message .= "Contact Details: ";
$message .= "\n";
$message .= "\n";
$message .= "Name: ";
$message .= $from_name;
$message .= "\n";
$message .= "Position: ";
$message .= $position;
$message .= "\n";
$message .= "Email: ";
$message .= $EmailFrom;
$message .= "\n";
$message .= "Phone: ";
$message .= $phone;
$message .= "\n";
$message .= "\n";
// send the message
mail("$to_name<$to_email>", $subject, $message, $headers);
print "Form sent successfully";
}
}
?>
<?
switch ($action) {
case "send":
sendMail();
showForm();
break;
default:
showForm();
}
?>
<div id="footer">
</div>
</div>
</body>
Start your php page with this code
if (!isset($_GET['id']) || empty($_GET['id']))
{
die("Bad Request");
}
This should solve your problem