Jump to content

Emailing and uploading with php


Darkleo

Recommended Posts

The script would have to upload the file(s) to your server and then attach it/them.  Do a search on "File Upload".

 

Once you have that, you need a way to attach the file to the message.  The simplest way to handle email attachments and a WHOLE BUNCH more is to use PHPMailer (http://phpmailer.codeworxtech.com/) which is a free PHP Class.

Can you just give me some steps to do this, or at the most the code - there is no way that I could put the upload code and the phpmailer scripts together.

 

If you have phpmailer working this code will work for you:

 

<?php 

$username = $_GET['username'];
$id = $_GET['id'];

$error_stat = 0; 
$name_message = '';


if (isset($_POST['submit'])) { 

$name = $_POST['name']; 
$email = $_POST['email']; 
$enquiry = $_POST['enquiry']; 




//Error checking 

//Username check) 
if (empty($name)) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a username
$name_message = '*Please enter a name*';
} 

//Then, only run the query if there were no errors (if $error_stat still equals 0) 
if ($error_stat == 0) { 

    echo "<h3>Enquiry was Successful</h3>"; 
   echo "<p>Thankyou</p>"; 
  	echo "<a href=\"index.php\">Back to main page</a>";
  	
   move_uploaded_file($_FILES['userfile']['tmp_name'],$_FILES['userfile']['name']);


require_once('class.phpgmailer.php');
$mail = new PHPGMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = 'ssl://smtp.gmail.com'; // SMTP servers
$mail->FromName = '#########'; 
$mail->AddAddress($email);
$mail->Subject = '########';
$mail->AddAttachment($_FILES['userfile']['name']);   //
$mail->Body = "Job Application from:\n\nName: $name\n";  
$mail->Send();
}
}

//Then, for the form, only show it if 1) the form hasn't been submitted yet OR 2) there is an error 
if (!isset($_POST['submit']) || $error_stat == 1) { 

$account = mysql_fetch_array(mysql_query("SELECT * FROM employers WHERE username='$username'"));

$job = mysql_fetch_array(mysql_query("SELECT * FROM job WHERE username='$username' AND id='$id'")); 

?> 

<!--this will show whatever is in the $message variable -->                    
<form method="post" class="registerform" action="" enctype="multipart/form-data">  

<fieldset>   
<p align="left"><span class="jobs"><span class="navyboldtxt">
<font face="Verdana" size="2">Apply for Job</font></span></span></p>
<span class="jobs"><span class="navyboldtxt">
<hr class="hr_blue"/>
</span></span>
<p></span>Direct Enquiry:</p>


<fieldset>
<p><label for="jobtitle">Job Title:</label> 
<input readonly name="jobtitle" type="text" id="jobtitle" value="<?php echo $job['jobtitle']; ?>"/> 
</fieldset> 

<fieldset>
<p><label for="email">Application being sent to:</label> 
<input name="email" type="text" id="email" value="<?php echo $account['email']; ?>"/> 
</fieldset> 




<fieldset>

<p><label for="name">Your Name:</label> 
<input name="name" type="text" id="name" maxlength="30" value="<?php echo $_POST['name']; ?>" />  
<span class="redboldtxt"><?php echo "$name_message";?></span></p>
</fieldset> 




<fieldset> 
<label for="comments">Additional Comments (Optional)</label> 
<textarea rows="2" name="comments" cols="20" /><?php echo $_POST["enquiry"]; ?></textarea>

<p></p>
</fieldset> 

<fieldset> 
<label for="Upload">Upload Application Form</label> 
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="9000000" /> 
<input type="file" name="userfile" size="50" value="90000000" /></td> 
</fieldset> 

<fieldset> 
<p></p> 
<p class="submit"><input type="submit" name="submit" value="Submit Enquiry" />
</fieldset> 

</form> 
<?php 
} 
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.