View Full Version : Mail Form
gcooper79
04-07-2009, 09:22 PM
Hi everyone,
I'm hoping someone will be able to help me. I am looking to create a form that will let the user attach a file by browsing their computer and then emailing the attachment to me by pressing a submit button. I would also like a pop up box confirming that the email has been sent.
I have looked all over the web trying to find an answer but to no avail. I have no script experience at all so would be very grateful for any help.
Thanks in advance.
Graeme
Do you have the email form already, and just looking for the extension, or do you need all the code?
Go here: http://us.php.net/manual/en/function.mail.php, and press CTRL+F in your browser, then type attach.
Schmoopy
04-08-2009, 12:04 AM
press CTRL+F in your brother
Haha :D
gcooper79
04-08-2009, 06:56 AM
Do you have the email form already, and just looking for the extension, or do you need all the code?
Go here: http://us.php.net/manual/en/function.mail.php, and press CTRL+F in your brother, then type attach.
Hi Nile,
Thanks for the quick reply. I had a look at the links you suggested, but I'm still confused.
I need the email form as well as the script. I tried to create one using the code below
<form action="mail.php" method="post">
Attachment: <input type="file" values="" name="myname"></p>
<input type="submit" value="Submit" name="submit">
</form>
gcooper79
04-09-2009, 07:17 PM
ok, I found this form on the net that does what I need but the information that the user fills out doesn't appear in the email, only the attachment. Can someone have a look at the code and tell me what I'm doing wrong.
thanks in advance,
Graeme
Form code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body style="padding:3px; margin:0px;" bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0" border="0" width="440">
<tr><td style="height:10px"></td></tr>
<tr>
<td colspan="2" style="text-align:justify; line-height:15px;" class="body">
<form name="frm" method="POST" action="careersuccess.php" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td width="23%" class="body"> Name</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strname" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Address</td>
<td width="3%" class="body">:</td>
<td width="74%"><textarea cols="16" name="straddress"></textarea></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> City</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strcity" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> State</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strstate" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Contact No</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="strno" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Email</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="text" name="stremail" class="textfield"></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Comments</td>
<td width="3%" class="body">:</td>
<td width="74%"><textarea cols="16" name="strcomments"></textarea></td>
</tr>
<tr><td style="height:3px"></td></tr>
<tr>
<td width="23%" class="body"> Resume</td>
<td width="3%" class="body">:</td>
<td width="74%"><input type="file" name="strresume"></td>
</tr>
<tr><td style="height:10px"></td></tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="Send" name="submit" onClick="return validate();"> <input type="reset" value="Reset" name="reset">
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td colspan="2" align="center"> </td>
</tr>
</table>
</body>
</html>
php code
<?php
$strname=ucfirst($_REQUEST["strname"]);
$straddress=ucfirst($_REQUEST["straddress"]);
$strcity=ucfirst($_REQUEST["strcity"]);
$strstate=ucfirst($_REQUEST["strstate"]);
$phone=$_REQUEST["strno"];
if($phone != ""){ $strno=$phone; } else { $strno="-"; }
$stremail=$_REQUEST["stremail"];
$strcomments=ucfirst($_REQUEST["strcomments"]);
$filename=$_FILES["strresume"]["name"];
$filetype=$_FILES["strresume"]["type"];
$filesize=$_FILES["strresume"]["size"];
$filetemp=$_FILES["strresume"]["tmp_name"];
if($filetype=="application/octet-stream" or $filetype=="text/plain" or $filetype=="application/msword")
{
$message= '
<table cellspacing="0" cellpadding="8" border="0" width="400">
<tr>
<td colspan="2"></td>
</tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strname.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Address</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$straddress.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>City</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strcity.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>State</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strstate.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Contact No.</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strno.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Email</strong></td>
<td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$stremail.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
<tr bgcolor="#eeeeee">
<td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Comments</strong></td>
</tr>
<tr bgcolor="#eeeeee">
<td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strcomments.'</td>
</tr>
<tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr>
</table>
';
// MAIL SUBJECT
$subject = "Mail with doc file attachment";
// TO MAIL ADDRESS
$to="to@mail.com";
/*
// MAIL HEADERS
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: Name <name@name.com>\n";
*/
// MAIL HEADERS with attachment
$fp = fopen($strresume, "rb");
$file = fread($fp, $strresume_size);
$file = chunk_split(base64_encode($file));
$num = md5(time());
//Normal headers
$headers = "From: Name<name@name.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// This two steps to help avoid spam
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
// With message
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";
// Attachment headers
$headers .= "Content-Type:".$strresume_type." ";
$headers .= "name=\"".$strresume_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$strresume_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";
// SEND MAIL
@mail($to, $subject, $message, $headers);
fclose($fp);
echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#333333; font-weight:bold">Attachment has been sent Successfully.<br /></font>';
}
else
{
echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold">Wrong file format. Mail was not sent.</font>';
//echo "<script>window.location.href='careers.html';</script>";
}
?>
hai gcooper79,
This Is one method to mail sending
mailsending.php
<?php
$to = "somebodyelse@example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John sdrtsert wertwert wertwertwert wertwer</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
echo $message;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: my@example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
this is another format mailsending.php
<?
$realname_got = $_POST['realname'];//thease are the field names that are coming from previous page
$from = $_POST['email'];
$subject_got = $_POST['subject'];
$message_got = $_POST['comments'];
$sub="contactus form";
//echo $subject;
$message .= "<table border='1' align='center'><tr><td>Subject:</td><td>$sub</td></tr><tr><td>Name</td><td>$realname_got</TD></TR> <tr><td>EMAIL</td><td>$from</td></tr> <tr><td>SUBJECT</td><td>$subject_got</td></tr><tr><td>COMMENTS</td><td>$message_got</td></tr></table>";
$to = "somebody@mail.com";
//echo $message;
mail($to, $sub, $message_got, "From:$from/r/nReply-to:$from");
header("Location:contact-thankyou.html");
?>
try it
by anu
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.