need help with mail()
Posted on
16th Feb 2014 07:03 pm by
admin
hi i want to send an email with attaching pdf file using php. i have the following script but the problem with this is when i send an attachment it does to the specified address but that email is empty means there is no attachment as well as message. what i am doing wrong in this script help
Code: <form id="requestcv" name="form1" method="post" action="request2.php">
<div>
<label>Your Name:</label>
<input type="text" name="name" id="textfield" />
</div>
<div>
<label>Your Email:</label>
<input type="text" name="email" id="textfield2" />
</div>
<div class="actions">
<input class="actions" type="submit" name="request" id="button" value="Request CV" />
</div>
</form>
<p>
<?php
if($_POST['request'])
{
//echo "My cv has been sent to your email address.Please check your email after 15 minutes. Thank you for requesting my CV.";
$name = $_POST['name'];
$email = $_POST['email'];
$message = "Here is my CV you requested for.Please download attachment and view my cv.Thank you for using my services.";
$to = $email;
$subject = "This is from zafar portfolio";
$random_hash = md5(date('r', time()));
$headers = "From: address@yahoo.comrnReply-To: address@yahoo.com";
$headers .= "rnContent-Type: multipart/mixed; boundary="PHP-mixed-".$random_hash.""";
$attachment = chunk_split(base64_encode(file_get_contents("CV.pdf")));
$output = "
--PHP-mixed-$random_hash;
Content-Type: multipart/alternative; boundary='PHP-alt-$random_hash'
--PHP-alt-$random_hash
Content-Type: text/plain; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
Hello World!
This is the simple text version of the email message.
--PHP-alt-$random_hash
Content-Type: text/html; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
<h2>Hello World!</h2>
<p>This is the <b>HTML</b> version of the email message.</p>
--PHP-alt-$random_hash--
--PHP-mixed-$random_hash
Content-Type: application/pdf; name=CV.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--PHP-mixed-$random_hash--";
//mail($to, $subject, $message, $output, $headers);
if (mail($to, $subject,$message, $output, $headers)) {
echo 'Mail sent';
} else {
echo 'Mail NOT sent';
}
}
?>
No comments posted yet
Your Answer:
Login to answer
287
50
Other forums
How to generate a random array of integers subject to a certain constraint
I am writing a program that asks the user to enter an integer N and then generates a random array of
Using mysql_real_escape_string for displayed content
On my website users can input data into a textarea and it will store it in the mysql database. But,
insert/update functions for mysql, what do you think?
I am working on two really simple functions that automatically generate (and execute) insert and upd
If statement help please.
Hello on my site I have 2 content boxes. 1 is for the main content (which is the biggest one) and th
Changing files over
Just thought I'd start with the new forums looking really nice .
Ok basically I've made this
Email logic not working
I would like to send an email using the php email() function then if it does execute i.e sends i wou
Does deleting the spmlog directory critical?
Hi Everyone,
Please, hope you could help me. We're having problems with the SAP backup. I
Final year project, please point me in the right direction
hi there for my final year project I'm aiming to build a php script shell to use as an expert system
Need help to identify this error please
:confused:Can anyone help me tell what this error message means? Maybe tell me where to look to fix
Select all entries from database that include a phrase
I have a database of clubs - one of the categories is meeting time and place
I would like to have