Warning: fopen(): Filename cannot be empty [duplicate] - php

Send email with attachment code was working fine recently we have transfer the file to another hosting server idk what happen it display the below error,
Warning: fopen(): Filename cannot be empty in /home/hugerecruitmetnt/public_html/validatecva.php on line 106
Warning: fread() expects parameter 1 to be resource, boolean given in /home/hugerecruitmetnt/public_html/validatecva.php on line 107
Warning: fclose() expects parameter 1 to be resource, boolean given in /home/hugerecruitmetnt/public_html/validatecva.php on line 148
Warning: Cannot modify header information - headers already sent by (output started at /home/hugerecruitmetnt/public_html/validatecva.php:106) in /home/hugerecruitmetnt/public_html/validatecva.php on line 150
<?php
$name = $_POST['fname'];
$initial = $_POST['mname'];
$surname = $_POST['lname'];
$gender = $_POST['gender'];
$dob = $_POST['dob'];
$nationality = $_POST['nationality'];
$address = $_POST['fulladdress'];
$passport = $_POST['passportno'];
$passexpiry = $_POST['passexpiry'];
$mobile = $_POST['mobile'];
$email_address = $_POST['email'];
$filename=$_FILES["newfile"]["name"];
$filetype=$_FILES["newfile"]["type"];
$filesize=$_FILES["newfile"]["size"];
$filetemp=$_FILES["newfile"]["tmp_name"];
if($filetype=="application/octet-stream" or $filetype=="text/plain" or $filetype=="application/msword" or $filetype=="application/zip" or $filetype=="application/pdf" or $filetype=="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
{
$message= '<table cellspacing="0" cellpadding="8" border="0" width="400">
<tr>
<td colspan="2"></td>
</tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fname.' '.$initial.' '.$surname.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Gender</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$gender.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Date Of Birth</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$dob.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>nationality</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$nationality.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Address</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fulladdress.'</td>
</tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Passport No</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$passportno.'</td>
</tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Passport Expiry</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$passexpiry.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Email</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$email.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Mobile</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$mobile.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
</table>
';
// MAIL SUBJECT
$subject = "Posted CV From ";
// TO MAIL ADDRESS
$to = 'email#email.com';
/*
// MAIL HEADERS
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: Name <name#name.com>\n";
*/
// MAIL HEADERS with attachment
$fp = fopen( $newfile, "rb");
$file = fread($fp, $newfile_size);
$file = chunk_split(base64_encode($file));
$num = md5(time());
//Normal headers
$headers = "From: $name<$email>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// This two steps to help avoid spam
$headers .= "Message-ID: <".$now." TheSystem#".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
// With message
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";
// Attachment headers
$headers .= "Content-Type:".$newfile_type." ";
$headers .= "name=\"".$newfile_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$newfile_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";
// SEND MAIL
#mail($to, $subject, $message, $headers);
fclose($fp);
header('Location: thankscv.php');
}
else
{
echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold">Wrong file format. Mail was not sent.</font>';
//echo "<script>window.location.href='careers.html';</script>";
}

Problem Solved
to hide the warning just use "#"
ex: #fopen, #fread, #fclose
Phew 3hrs wasted to solve this warning

Default size of uploading temp file is 2mb
Increase Size By
upload_max_filesize=2M
TO
upload_max_filesize=100M
in php.ini xampp, and after that restart xampp. I hope you will not get any errors and that the file will be read also.

Related

image not showing in email using php mail

I am trying to send email using php code mail is working file but image not coming into the mail. the image src path is coming with encoded string as below
<img style="width:100%" src="https://ci6.googleusercontent.com/proxy/NT6fQckS1LLRnuTUJnW0Fp2qUujk_Cpv9kV1hwoKQADwL8XU7fo4=s0-d-e1-ft#http://header.png" class="CToWUd a6T" tabindex="0">
<?php
$to = $_REQUEST['email'];
$subject = 'Winning prize';
$email_id = 'info#sample.com';
$headers = "From: " . strip_tags($email_id) . "\r\n";
$headers .= "Reply-To: " . strip_tags($email_id) . "\r\n";
$headers .= "CC: satishv#sample.com";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html>
<head>
<title></title>
</head>
<body>
<div style="border:1px solid #e96000; width: 600px;">
<table style="color: #777;font-family: sans-serif;" width="600">
<tr>
<td style="padding:0px 0">
<img style="width: 100%;" src="header.png">
</td>
</tr>
<tr>
<td><span style="font-family: sans-serif;">Hey</span><span style="font-family: sans-serif;margin-left: 5px;">'.$address['customer_name'].'!,</span></td>
</tr>
<tr>
<td style="padding:20px 0 0 20px"><span style="font-family: sans-serif;">Congratualtion! The product is Yours.</span></td>
</tr>
</table>
<table style="color: #777;font-family: sans-serif;text-align: center;" width="600">
<tr>
<td colspan="4" style="padding: 30px 0;border-top: 1px solid #e96000;border-bottom: 1px solid #e96000;"><span>Once Your Package ships we will send your a tracking number Once Your Package ships we will send your a tracking number Once Your Package ships we will send your a tracking number </span></td>
</tr>
</table>
</div>
</body>
</html>';
$result = mail($to, $subject, $message, $headers);
?>
the above code is working file just image not coming into the mail
Most of the email clients block the image. But still, you can show the image. You have to use Absolute image source URL. For an example
<img style="width: 100%;" src="header.png">
change to
<img style="width: 100%;" src="http://www.YourSite.com/header.png">
Please be sure that the image exists in the path.

php error fopen(): Filename cannot be empty in

Send email with attachment code was working fine recently we have transfer the file to another hosting server idk what happen it display the below error,
Warning: fopen(): Filename cannot be empty in /home/hugerecruitmetnt/public_html/validatecva.php on line 106
Warning: fread() expects parameter 1 to be resource, boolean given in /home/hugerecruitmetnt/public_html/validatecva.php on line 107
Warning: fclose() expects parameter 1 to be resource, boolean given in /home/hugerecruitmetnt/public_html/validatecva.php on line 148
Warning: Cannot modify header information - headers already sent by (output started at /home/hugerecruitmetnt/public_html/validatecva.php:106) in /home/hugerecruitmetnt/public_html/validatecva.php on line 150
<?php
$name = $_POST['fname'];
$initial = $_POST['mname'];
$surname = $_POST['lname'];
$gender = $_POST['gender'];
$dob = $_POST['dob'];
$nationality = $_POST['nationality'];
$address = $_POST['fulladdress'];
$passport = $_POST['passportno'];
$passexpiry = $_POST['passexpiry'];
$mobile = $_POST['mobile'];
$email_address = $_POST['email'];
$filename=$_FILES["newfile"]["name"];
$filetype=$_FILES["newfile"]["type"];
$filesize=$_FILES["newfile"]["size"];
$filetemp=$_FILES["newfile"]["tmp_name"];
if($filetype=="application/octet-stream" or $filetype=="text/plain" or $filetype=="application/msword" or $filetype=="application/zip" or $filetype=="application/pdf" or $filetype=="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
{
$message= '<table cellspacing="0" cellpadding="8" border="0" width="400">
<tr>
<td colspan="2"></td>
</tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fname.' '.$initial.' '.$surname.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Gender</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$gender.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Date Of Birth</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$dob.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>nationality</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$nationality.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Address</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$fulladdress.'</td>
</tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Passport No</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$passportno.'</td>
</tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Passport Expiry</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$passexpiry.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Email</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$email.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Mobile</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$mobile.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
</table>
';
// MAIL SUBJECT
$subject = "Posted CV From ";
// TO MAIL ADDRESS
$to = 'email#email.com';
/*
// MAIL HEADERS
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: Name <name#name.com>\n";
*/
// MAIL HEADERS with attachment
$fp = fopen( $newfile, "rb");
$file = fread($fp, $newfile_size);
$file = chunk_split(base64_encode($file));
$num = md5(time());
//Normal headers
$headers = "From: $name<$email>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// This two steps to help avoid spam
$headers .= "Message-ID: <".$now." TheSystem#".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
// With message
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";
// Attachment headers
$headers .= "Content-Type:".$newfile_type." ";
$headers .= "name=\"".$newfile_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$newfile_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";
// SEND MAIL
#mail($to, $subject, $message, $headers);
fclose($fp);
header('Location: thankscv.php');
}
else
{
echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold">Wrong file format. Mail was not sent.</font>';
//echo "<script>window.location.href='careers.html';</script>";
}
Problem Solved
to hide the warning just use "#"
ex: #fopen, #fread, #fclose
Phew 3hrs wasted to solve this warning
Default size of uploading temp file is 2mb
Increase Size By
upload_max_filesize=2M
TO
upload_max_filesize=100M
in php.ini xampp, and after that restart xampp. I hope you will not get any errors and that the file will be read also.

What is wrong with my PHP email code; it won't redirect to thank you page [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
Curious as to what is wrong with the following php code which sends an email when a contact form is filled out and submitted. The email arrives perfectly but instead of redirecting it gives the following error:
Warning: Cannot modify header information - headers already sent by (output started at /home4/ranchoba/public_html/marvan/marvan/send.php:1) in /home4/ranchoba/public_html/marvan/marvan/send.php on line 112
I've tried calling the php file by the action in the form as well as by placing a in the very first line of the page. Neither one works.
PHP Code:
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
//if the form is submitted, go ahead and send the email to ops
ob_start();
if ($_POST['is_form_submitted'] == "yes")
{
//Send email to ops of this request-----------------------------------------------------------------------------------
// multiple recipients
$to = 'blah#gmail.com';
// subject
$subject = "Contact Request: ".$_POST['name'];
// message
$message = '
<html>
<head>
<title>Re: Marvan Site Contact Request</title>
<style type="text/css">
<!--
.style4 {font-family: Arial, Helvetica, sans-serif; font-size: 12; }
.style5 {font-size: 12}
.style6 {font-family: Arial, Helvetica, sans-serif; font-size: 12; font-weight: bold; }
-->
</style>
</head>
<body>';
$message=$message.'
<table width="450" border="0" align="center" cellpadding="4" cellspacing="0" style="border-color:#CCCCCC; border-style:solid; border-width:1px; background-color:#FFFFFF; padding-top:3px;">
<tr>
<td width="430" style="height:auto;" valign="top">';
$message=$message.'<img src="http://www.blah.com/blah/images/logo.png">';
$message=$message.'<hr>';
$message=$message.'<h2 style="font-family:Arial, Helvetica, sans-serif; color:#B58736">Contact Request </h2>';
$message=$message.'
<table width="486" border="0" align="center" cellpadding="4" cellspacing="2">
<tr>
<td colspan="4" valign="top"><div align="left" class="style4"><span style="color:#000000; font-weight:bold;">Contact Details: </span></div></td>
</tr>
<tr>
<td width="145" valign="top"><div align="left" class="style4">Name :</div></td>
<td width="1" valign="top"><span class="style5"></span></td>
<td width="984" colspan="2" valign="top"><div align="left" class="style6">';
$message = $message. $_POST['name'];
$message = $message.'</div></td>
</tr>
<tr>
<td valign="top"><div align="left" class="style4">Email :</div></td>
<td valign="top"><span class="style5"></span></td>
<td colspan="2" valign="top"><div align="left" class="style6">';
$message = $message. $_POST['email'];
$message = $message.'</div></td>
</tr>
<tr>
<td valign="top"><div align="left" class="style4">Subject :</div></td>
<td valign="top"><span class="style5"></span></td>
<td colspan="2" valign="top"><div align="left" class="style6">';
$message = $message. $_POST['subject'];
$message = $message.'</div></td>
</tr>
<tr>
<td valign="top"><div align="left" class="style4">Phone :</div></td>
<td valign="top"><span class="style5"></span></td>
<td colspan="2" valign="top"><div align="left" class="style6">';
$message = $message. $_POST['phone'];
$message = $message.'</div></td>
</tr>
<tr>
<td valign="top"><div align="left" class="style4">Message :</div></td>
<td valign="top"><span class="style5"></span></td>
<td colspan="2" valign="top"><div align="left" class="style6">';
$message = $message. $_POST['message'];
$message = $message.'</div></td>
</tr>';
$message = $message.'
<tr> <tr><td colspan="4" valign="top"><span class="style5"></span></td>
</tr>';
$message = $message.'
</table>
<br /></td>
</tr>
</table>
<p> </p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
/* $headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";*/
/* $headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";*/
// Mail it
mail($to, $subject, $message, $headers);
//end of Send Email to Client --------------------------------------------------------------
//redirect to the thank you page
header('Location: http://www.blah.com/blah/thank-you.php');
} //end of if ($_POST['is_form_submitted'] == "yes")
?>
Maybe you have space before <?php tag in your scripts. Check it please and remove them. Also use UTF-8 file encoding without BOM
It is best to find where you are outputting a space or line that is causing the header() to fail. But if you cannot, try this to clear the buffer before header().
if (ob_get_length() > 0 ) {
ob_clean();
flush();
}

Email attachment won't allow certain types

I'm attempting to write this code for an where it can play as an application form and submits the information entered by the user through PHP mail. But I continue to get this error where it states that the file type is not allowed.
Some of the reserved words are not highlighted, so I'm not sure if the program doesn't recognized their functions. I checked the basename function, where basename is not highlighted as it should be. So I tried to use pathinfo, but I don't want the whole path just the the basename of it. Is it because it is not encoding correctly so it can't recognize the file type?? Please check my check my code.....
<?php
if(!empty($_FILES['resume_name']['name'])){
$file_name=$_FILES['resume_name']['name'];
$temp_name=$_FILES['resume_name']['tmp_name'];
$file_type=$_FILES['resume_name']['type'];
$file_size=$_FILES['resume_name']['size'];
$base=basename($file_name);
$extension= pathinfo($base, PATHINFO_EXTENSION);
$allowed_ext=array(".doc",".docx",".pdf",".zip",".jpeg",".jpg",".txt");
if (array_intersect($extension,$allowed_ext)){
$from=$_POST['email'];
$to="travis.dacosta1#gmail.com";
$subject= $_POST['departments'];
$message='
<table cellspacing="0" cellpadding="8" border="0" width="400">
<tr>
<td colspan="2"></td>
</tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$first_name.'</td>
</tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$last_name.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Email</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$email.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Departments</strong></td>
</tr>
<tr bgcolor="#eeeeee">
<td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$departments.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Qualifications</strong></td>
</tr>
<tr bgcolor="#eeeeee">
<td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$qualifications.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
</table>
';
$file=$temp_name;
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid=md5(uniqid(time()));
$header = "From: ". $from. "\r\n";
$header .= "Reply-To: ". $replyto. "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .="Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type: ".$file_type."; name=\"".$file_name."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: resume_name; filename=\"".$file_name."\"";
$header .= $content."\r\n\r\n";
if(#mail($to, $subject, $message, $header)){
echo "Success";
}
else{
echo "Fail";
}
}
else {
echo "File Type Not Allowed!!";
}
}
else{
echo "No File Posted!!";
}
}
exit();
?>
array_intersect takes an array as it first parameters. pathinfo($base, PATHINFO_EXTENSION); gives a String, not an Array.
You can try in_array:
if (in_array($extension, $allowed_ext)) {
....
}
Also, your $allowed_ext should be without dots:
$allowed_ext = array("doc", "docx", "pdf", "zip", "jpeg", "jpg", "txt");
because pathinfo($base, PATHINFO_EXTENSION); gives the extension without the dot.
http://www.php.net/manual/en/function.pathinfo.php
Email attachment won't allow certain types because you already specified some file extensions in your code.So you may not allow other than these file extensions.
Also remove dots from your file extension You can add more file extensions here.
$allowed_ext=array("doc","docx","pdf","zip","jpeg","jpg","txt");
$allowed_ext=array("doc","docx","pdf","zip","jpeg","jpg","txt");
remove dot in the extence
I actually figured out what was wrong. You all will laugh but, I was working on the same document but from a different directory. So the revisions I was making wasn't being uploaded to the server. After taking all of your suggestions it was able to upload the file perfectly.

Changing php form to submit a styled email (HTML email)

When I submit my form, I receive the email in plain text and not quite in the format I'd like it to be. I'd like it to at least have color to the body and arrange the email so that its neater.
on the contact.php form ... this is what I currently have:
$msg = "You have been contacted by $name with regards to Accommodation.
They passed verification and their message is as follows." . PHP_EOL . PHP_EOL;
$msg .= "$comments" . PHP_EOL . PHP_EOL;
$msg .= "You can contact $name via email, $email or via phone $phone." .
PHP_EOL . PHP_EOL;
$msg .= "We want to stay from the $dayin to the $dayout" . PHP_EOL .
PHP_EOL;
Why is this form using $msg? I've seen in other forms, they use $message.
Can I add CSS styling to the above form?
I also see:
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
Would I need to change "plain" to "HTML"?
Any suggestions or examples would be great!
EDIT:
Ok so now my header are:
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . "\r\n" . PHP_EOL;
$headers .= "Content-type: text/html;charset=iso-8859-1" . "\r\n" .
PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
Do I need PHP_EOL in each header?
My $msg looks like:
$msg = '<style type="text/css">
<!--
.style {
font-family: Arial;
font-size: 12px;
color: #4D241E;
}
body {
background-image: url();
background-color: #F1EAE4;
}
.style1 {font-size: 14px}
-->
</style>
<p> </p>
<table width="420" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td><table width="100%" border="0" cellpadding="8" cellspacing="0" bgcolor="#E7D3AF"
class="style">
<tr>
<td colspan="2" valign="top"><div align="center"><strong><span
class="style1">Submission / Enquiry from your website</span><br>
........................................................................
</strong><br>
</div></td>
</tr>
<tr>
<td width="32%" valign="top"><div align="left"><strong>Date Submitted</strong>
</div></td>
<td width="68%" valign="top">'. date("F j, Y, g:i a") .'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Name</strong></div></td>
<td valign="top">'.$_POST['name'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Email</strong></div></td>
<td valign="top">'.$_POST['email'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Phone</strong></div></td>
<td valign="top">'.$_POST['phone'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Day in</strong></div></td>
<td valign="top">'.$_POST['dayin'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Day out</strong></div></td>
<td valign="top">'.$_POST['dayout'].'</td>
</tr>
<tr>
<td valign="top"><div align="left"><strong>Comments</strong></div></td>
<td valign="top">'.$_POST['comments'].'</td>
</tr>
</table></td>
</tr>
</table>
';
EDIT:
MY NEW HTML EMAIL DESIGN:
<table width="600" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="12" height="14"></td>
<td width="140"></td>
<td width="432"></td>
<td width="16"></td>
</tr>
<tr>
<td height="71"></td>
<td colspan="2" align="center" valign="middle" bgcolor="#F5F5F5"><span style="font-
family:Arial; font-size:18px; color:#333333;"><strong>Submission from</strong>
</span><br />
<span style="font-family:Arial; font-size:16px; color:#f9930f;">
<em>Your website</em></span></td>
<td></td>
</tr>
<tr>
<td height="16"></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Name:</strong></span></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['name'].'</span></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Email:</strong></span></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['email'].'</span></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Phone:</strong></span></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['phone'].'</span></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Day in:</strong></span></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['dayin'].'</span></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Day out:</strong></span></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['dayout'].'</span></td>
<td></td>
</tr>
<tr>
<td height="30"></td>
<td valign="middle"><span style="font-family:Arial; font-size:12px; color:#333333;">
<strong>Comments:</strong></span></td>
<td> </td>
<td></td>
</tr>
<tr>
<td height="190"></td>
<td colspan="2" valign="top"><span style="font-family:Arial; font-size:12px;
color:#333333;">'.$_POST['comments'].'</span></td>
<td></td>
</tr>
<tr>
<td height="20"></td>
<td> </td>
<td> </td>
<td></td>
</tr>
</table>
Now when I add this form in my php and submit my form ... I receive my submission that doesn't look like the table layout like above.
You can use the following headers. These will allow you to just put normal HTML in your message.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <example#example.com>' . "\r\n";
$headers .= 'Cc: example two#example.com' . "\r\n";
Yep you are going to have to use
Content-type:text/html;charset=iso-8859-1\r\n
It might be a good idea to provide your email in both HTML and text formats as not all email applications support HTML, and many others support it poorly.
To do so use this header instead. The boundary thing is what separates the HTML and text versions in the email, the line below generates a unique code which is suitable for this purpose
$boundary = md5(date('r', time()));
$headers .= "\r\nContent-Type: multipart/alternative; boundary=$boundary."\"";
Before the text version of the email post this code, note the "--" at the begging. You use the same boundary throughout the email.
--<?php echo $boundary; ?>
Before the HTML version post the same code again
There is a good template you can use here
http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php

Categories