Page 1 of 1
sending email using php code
Posted: Wed Jan 05, 2011 6:35 am
by frnds
Code: Select all
$fileatt = bla bla // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = $_FILES['userfile']['name']; // Filename that will be used for the file as the attachment
$email_from = $_POST['name']." ".$_POST['email']; // Who the email is from
$email_subject = $_POST[applyfor];
$email_message ='
<table cellpadding="3" cellspacing="1" border="0" width="600">
<tr>
<td>Dear HR , '.$_POST[name].' has sent the Resume </td>
</tr>
<tr>
<td width="120">Name</td>
<td>'.$_POST[name].'</td>
</tr>
<tr>
<td width="120">Age</td>
<td>'.$_POST[age].'</td>
</tr>
<tr>
<td width="120">Date of Birth</td>
<td>'.$_POST[date].'/'.$_POST[month].'/'.$_POST[year].'</td>
</tr>
<tr>
<td width="120">Gender</td>
<td>'.$_POST[gender].'</td>
</tr>
<tr>
<td width="120">Nationality</td>
<td>'.$_POST[nation].'</td>
</tr>
<tr>
<td width="120">Country of Residence</td>
<td>'.$_POST[country].'</td>
</tr>
<tr>
<td width="120">Contact Telephone</td>
<td>'.$_POST[phone].'</td>
</tr>
<tr>
<td width="120">Email</td>
<td>'.$_POST[email].'</td>
</tr>
<tr>
<td width="120">Applying For</td>
<td>'.$_POST[applyfor].'</td>
</tr>
</table>
';
$email_to = 'aaaaaa@jjj.com'
//adds the e-mail address of the sender
$headers = "From: ".$_POST[email];
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"utf-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}\n";
unset($data);
unset($file);
unset($fileatt);
unset($fileatt_type);
unset($fileatt_name);
@mail($email_to, $email_subject, $email_message, $headers);
hi all
i am new to this forum . hope somebody will help me to solve my pblm. The above code is working fine . i am receiving email with attachment to the specified email id . but the pblm is along with the original attachment , i am reciving another attachment say 'ATTOOOO1.C' of size 208 B . I dont know why i am recieving tis . Pls help me to solve this . Any help is appreciated .
Thank you
Re: sending email using php code
Posted: Wed Jan 05, 2011 11:17 am
by Jade
Try changing the last line of your code and see if you're getting an error messages that may explain the additional attachment:
Code: Select all
//remove the @ in front of the mail function
mail($email_to, $email_subject, $email_message, $headers);
Re: sending email using php code
Posted: Wed Jan 05, 2011 4:52 pm
by phphelpme
To me this problem normally falls to some sort of antivirus either on the sending machine or by the recieving machine. Try uninstalling your antivirus program on your recieving machine and then install again with email scanner to see if this solves the problem.
I had this simular issue when I installed a new version of a popular AV program. From your coding nothing seems out of place and as you said you are clearly getting your messages through. Also, it can depend on your settings for your mail client such as Outlook 2003/2007 etc or Microsoft Outlook etc.
Re: sending email using php code
Posted: Thu Jan 06, 2011 12:24 am
by frnds
thank you for the replies .
tried changing the @ sign , but it didnt work .
uninstalling the AV program also didnt help .
somebody pls help with some other way .
Thank you .
Re: sending email using php code
Posted: Thu Jan 06, 2011 10:19 am
by phphelpme
How are you recieving this email? through which software email client?
Such as outlook express, microsoft outlook or thunderbird etc or gmail etc etc
Also, what is your exchange called for sending the emails?
I have tested your email coding and it works just fine for me on my system and I use exchange 2007, gmail and microsoft outlook client.
Have you tried recieving your email from different mail clients to rule out a client-side issue? like recieving through gmail or another software program?
Regards PHP mail() it uses Sendmail which sends default plain text emails anyway if I am correct.
The main question here is how are you recieving your mail???
Best wishes
Re: sending email using php code
Posted: Sun Jan 16, 2011 1:06 am
by frnds
i am receiving the email using Microsoft outlook , exchange 2007 .
Re: sending email using php code
Posted: Sun Jan 16, 2011 1:42 am
by frnds
Hi phphelpme , thanks for your suggestion , tried using through gmail .While receiving through gmail , i am getting only the original attachment . its fine.
But when recieving through Outlook , receiving an attachment 'ATTOOOO1.C' of size 208 B along wit original ataachment .
Somebody pls help me to solve this . Any help will be appreciated .
Re: sending email using php code
Posted: Mon Jan 17, 2011 9:07 am
by phphelpme
hi frnds,
well, if you are recieving your mail correctly to another mail client, (gmail) then I can only assume that your outlook is running some type of addon which is scanning the email as your are recieving it and converting it as the attachment to the email.
A big common aspect of this would be AV's (Anti Virus Programs) that do this in outlook.
You can try uninstall any antivirus software you have temporary while you test the recieved email again. I do believe this is what is causing your attachment. I can think of nothing else as another client recieves this ok, your coding is fine and nothing needs changing.
It must be something running within your mail client (Outlook). If you read the forums for microsoft outlook you can see all of them point to this solution mainly.
I hope this helps and you can get this sorted. As I said in a previous reply, I did have this problem some time ago and it was my AV program that was causing this. SO I uninstalled this program, installed using custom settings and asked not to install such things as link scanner, email scanner on incoming and outgoing and it worked. SO I re-enabled the link scanner etc but left the email scanner off.
You could try using a totally different AV to test this too just to make sure. As that would then not leave you vunerable in any way or form.
Kind regards,
PHPHelpMe!
Re: sending email using php code
Posted: Wed Jan 19, 2011 12:02 am
by frnds
Thank u phphelpme for your suggestion . will ry to do that and sort my problem .
Regards
frnds
Re: sending email using php code
Posted: Wed Jan 26, 2011 2:51 am
by Kath3rine
I don’t know if this is going to work. Try to disable your anti-virus because I think it is the cause of the problem. Change also the last line of the code you are using. An error is maybe occurring with this.