Jump to content

attachment email


Recommended Posts

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

<?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

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.