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 Like 50 Dislike
Previous forums Next forums
Other forums

php global variable
how can we create global variable so we can use its value in any form.. Please give example to

search function
HI guys,

if anyone could point us in the right direction of how to do this, or provide some t

Code error with Index.php
Error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/runevid/public_

Download Image from URL and Upload it
Ok, I have been googling for the last 1/2 hour trying to figure this out, Most likely I'm just not s

Help Ordering Arrays
Hi, I have 3 arrays as shown below.

Code: $users = $this->get_latest_users();
$flir

Comment Mod System Effects all rows...
Sorry if its confusing but here is whats going on: I have a table in a database called comments and

question about n
I was looking at some of the things you could do with php and one of the things I have tried is n.<

Save remote XML to local website folder
Hi, I hope you can help me out. I would like to be able to pull an XML file from another site and t

update sql when refresh - php
hi
I have made a table (attachement)

the users can update the sql database using + or x bu

Hit counter updating once per IP - IP HIT COUNTER
I have a hit counter, for the amount of views on a tutorial.
It'll do the query and then do..

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash