|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
PHP form mail with attachment - blank page
I am coding a PHP form mail with attachment for a client of mine. The form seems to have run into an issue. After the form is submitted with attachment it displays a blank page. However if I submit the form without any attachment then it works fine. Here is the HTML and PHP code that we are using:
Form code: Code:
<form action="career.php" method="post" enctype="multipart/form-data">
<?php if(isset($errormsg)){
?>
<div class="errormsg"><strong>ERROR: </strong><?php echo $errormsg; ?></div>
<div class="clear"></div>
<br />
<?php
}
?>
<fieldset><legend><span class="fieldheader">Personal Details</span></legend>
<table align='left' width='100%' cellpadding='2' cellspacing='2' border="0">
<tr>
<td width='50%' align='left' class='row1'><strong>Full Name: <span class="required">*</span></strong></td>
<td width='50%' align='left' class='row1'><input type='text' name='name' /></td>
</tr>
<tr>
<td width='50%' align='left'><strong>Email: <span class="required">*</span></strong></td>
<td width='50%' align='left'><input type='text' name='email' /></td>
</tr>
</table>
</fieldset>
<br />
<fieldset>
<table align='left' width='100%' cellpadding='2' cellspacing='2' border="0">
<tr>
<td width='50%' align='left'><strong>Upload Resume: </strong><br />
Allowed file types - MS Word & PDF files
</td>
<td width='50%' align='left'><input type="file" name="strresume" /></td>
</tr>
</table>
</fieldset>
<table align='left' width='100%' cellpadding='2' cellspacing='2' border="0">
<tr>
<td width='50%' align='right'><input type='submit' value='Submit' class='bluebutton' name='submit' /></td>
<td width='50%' align='left'><input type='reset' value='Reset' class='redbutton' name='reset' /></td>
</tr>
</table>
</form>
PHP Code: Code:
<?php
if(isset($_POST['submit']) AND $_POST['submit'] == "Submit"){
print_r($_FILES);
// IF FILE IS SET TO BE UPLOADED THEN GET ITS INFORMATION
$strresume_name = $_FILES['strresume']['name'];
$strresume_type = $_FILES['strresume']['type'];
$strresume_size = $_FILES['strresume']['size'];
$strresume_temp = $_FILES['strresume']['tmp_name'];
// CHECK IF ALL REQUIRED FIELDS ARE FILLED
if(empty($_POST['name']) OR empty($_POST['email']) ){
$errormsg = "You forgot to fill one or more required fields";
include("form.inc");
}
// RUN CHECKS TO CONFIRM IF THE UPLOADED FILE IS ACCEPTABLE FORMAT
elseif(!empty($strresume_type)){
if(($strresume_type != "application/pdf") AND ($strresume_type != "application/msword") AND ($strresume_type != "application/vnd.openxmlformats")){
// FILE IS IN NON-ACCEPTABLE FORMAT THROW ERROR
$errormsg = "The submitted resume is not in MS Word or PDF format. Please try again";
include("form.inc");
}
}else{
echo "Send mail";
}
}else{
// DISPLAY THE FORM
include("form.inc");
}
?>
The above code works fine if I submit the form without attachment. It does throw an error when the filetype is not Word or PDF. But if I attach a PDF file the page comes out blank when it should display the message "Send mail". The print_r($_FILES); too displays the result just fine. What am I doing wrong? I spent all day on this and am completely lost right now. Last edited by eludic : November 6th, 2009 at 12:53 PM. Reason: Better titling |
|
#2
|
||||
|
||||
|
Is error_reporting on?
Try this instead:
PHP Code:
|
|
#3
|
||||
|
||||
|
Basically what happened was that you uploaded a file, which means $strresume_type is true. But if it's a correct file type, there's nothing left for the code to do ... lots of nested if statements can catch you up very easily.
If I were writing this, I might change things a bit like so (in my mind it makes it clearer AND if your user has multiple validation errors you tell them all at once, versus making them submit it multiple times). You also reduce duplicate code a little bit: PHP Code:
|
|
#4
|
|||
|
|||
|
Thank You so much for replying. I get what you are tryin to suggest. I will implement the changes you have provide and shall see if that does the trick. Thanks again!
|
|
#5
|
|||
|
|||
|
That did the trick. Thank You so much!
Quote:
You were right. I made changes to my code, thanks again. |
|
#6
|
|||
|
|||
|
I have one final problem. When the form is submitted using punctuations like apostrophe then PHP cuts the submitted data for instance if the submission is L'Global then PHP only accepts L stripping the rest. I have tried addslashes() but that too does not work. That comes out with the output L\\ while 'Global is yet dropped. How do I fix this?
|
|
#7
|
||||
|
||||
|
Where is the last point in your code that the name is still intact?
|
|
#8
|
|||
|
|||
|
Thanks for your help. I managed to fix it.
|
|
#9
|
||||
|
||||
|
Nice job, remember to post back your solutions in case someone else has similar issues.
|
|
#10
|
|||
|
|||
|
True. The solution was that I did not set stripslashes correctly due to which the issue was happening. By going through the code I managed to fix it.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > Email with attachment form - blank page |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|