Darkleo Posted April 10, 2008 Share Posted April 10, 2008 I want a php email form that emails me and also attatches a file to the email. I already have the email part, so I was wondering if anyone could help with the attaching files and sending them on the same email. Link to comment https://forums.phpfreaks.com/topic/100546-emailing-and-uploading-with-php/ Share on other sites More sharing options...
doni49 Posted April 10, 2008 Share Posted April 10, 2008 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. Link to comment https://forums.phpfreaks.com/topic/100546-emailing-and-uploading-with-php/#findComment-514257 Share on other sites More sharing options...
Darkleo Posted April 10, 2008 Author Share Posted April 10, 2008 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. Link to comment https://forums.phpfreaks.com/topic/100546-emailing-and-uploading-with-php/#findComment-514277 Share on other sites More sharing options...
Cyberspace Posted April 11, 2008 Share Posted April 11, 2008 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 } ?> Link to comment https://forums.phpfreaks.com/topic/100546-emailing-and-uploading-with-php/#findComment-514330 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.