anthony-needs-you Posted May 1, 2009 Share Posted May 1, 2009 How do i create an email attachment using this script <?php error_reporting(E_NOTICE); function valid_email($str) { return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; } if($_POST['name']!='' && $_POST['telephone']!='' && $_POST['e_mail']!='' && $_POST['county']!='' && valid_email($_POST['e_mail'])==TRUE && strlen($_POST['message'])>5) { $to = '[email protected]'; $headers = 'From: '.$_POST['e_mail'].''. "\r\n" . 'Reply-To: '.$_POST['e_mail'].'' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Website Enquiry - contact page"; $name = "Name: " . $_POST["name"] . "\r\n"; $telephone = "Telephone: " . $_POST["telephone"] . "\r\n"; $county = "County: " . $_POST["county"] . "\r\n"; $repair = "Repair: " . $_POST["repair"] . "\r\n"; $enquiry = "Message: " . $_POST["message"] . "\r\n"; $body = "$name\n $telephone\n $repair\n $county\n $enquiry\n"; //$message = htmlspecialchars($_POST['message'] && $_POST['first_name'] && $_POST['last_name']); if(mail($to, $subject, $body, $headers)) {//we show the good guy only in one case and the bad one for the rest. echo '<div class="success-msg">Thank you '.$_POST['name'].'. Your message was sent</div>'; } else { echo '<div class="error-msg">Message not sent. Please make sure you\'re not running this on localhost and also that you are allowed to run mail() function from your webserver</div>'; } } else { echo '<div class="error-msg">Please make sure you filled all the required fields, that you entered a valid email and also that your message contains more then 5 characters.</div>'; } ?> this is the html upload <input name="photo" id="photo" size="30" type="file" class="fileUpload" /> Any help is appreciated Link to comment https://forums.phpfreaks.com/topic/156394-attachment-email/ Share on other sites More sharing options...
ignace Posted May 1, 2009 Share Posted May 1, 2009 <?php echo '<div class="error-msg">Message not sent. Please make sure you\'re not running this on localhost and also that you are allowed to run mail() function from your webserver</div>'; ?> You could eliminate mail() entirely so that you can send your e-mails even from localhost: http://chimit.mirrors.phpclasses.org/blog/package/14/post/2-Sending-email-using-SMTP-servers-of-Gmail-Hotmail-or-Yahoo-with-PHP.html Link to comment https://forums.phpfreaks.com/topic/156394-attachment-email/#findComment-823387 Share on other sites More sharing options...
anthony-needs-you Posted May 1, 2009 Author Share Posted May 1, 2009 does anyone know how i would attach an attachment to this email script? Link to comment https://forums.phpfreaks.com/topic/156394-attachment-email/#findComment-823438 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.