PHP Emails

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
I have this simple email script and for some reason the emails recieved have no body. Also, I put in the headers that it was from Jacob Walters but it shows up as Jacob@yahoo.com.
PHP:
$to = Ninjaferret666@yahoo.com;
$from = "Jacob Walters";
$headers = "from: $from\r\n";
$headers .= "Importance: High\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/alternative\r\n";
$message = "Your account has been deleted!";
$subject = "Account Deleted";
var $sent = mail($to,$subject,$message,$headers);
if ($sent) echo "Email Sent!";
else echo "Failed to Send!";
Please tell me why it is crewing up like this. I think it is because I put in the wrong content-type or some settings in the php.ini are wrong.
 

qwertzguy

New Member
Messages
4
Reaction score
0
Points
0
Hey,
Firstly content-type should be "text/plain;" in the header since you're only sending text (with multipart/alternative you need to identify each part in the message body, which is why you see a body because you don't have any part in your body.)
Secondly if you want the sender to be show as Jacob Walters, you still imperatively need an email address associated. However in most email progs or webinterface the email of the sender is not shown if a name is supplied. To do so simply set the from like this:
$from = '"Jacob Walters" <jacob@yahoo.com>';
Beware, it begins with single quote to open the string variable and if immediatly followed by double quote which is part of sender's identifier syntax. Also the email of the sender MUST exist and it is even better if the domain of the email corresponds to the domain of the php server sending this email, otherwise a lot of email progs will say it's an unsecured email or spam.


-Qwertzguy-
 
Last edited:

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
Thank you very much for your help. Since all the email I sent got filtered as spam I tried to mix up the headers and messed it up. :happysad: I added to your reputation. Also, how do you send an attachment with an email using php?
 
Last edited:

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
OMG, thank you. Sorry it took me so long to test it. I found how to send email attachments on Google. I donated 50 credits :)
 

erniehan

New Member
Messages
11
Reaction score
1
Points
3
Hey,
Firstly content-type should be "text/plain;" in the header since you're only sending text (with multipart/alternative you need to identify each part in the message body, which is why you see a body because you don't have any part in your body.)
Secondly if you want the sender to be show as Jacob Walters, you still imperatively need an email address associated. However in most email progs or webinterface the email of the sender is not shown if a name is supplied. To do so simply set the from like this:
$from = '"Jacob Walters" <jacob@yahoo.com>';
Beware, it begins with single quote to open the string variable and if immediatly followed by double quote which is part of sender's identifier syntax. Also the email of the sender MUST exist and it is even better if the domain of the email corresponds to the domain of the php server sending this email, otherwise a lot of email progs will say it's an unsecured email or spam.


-Qwertzguy-
 

erniehan

New Member
Messages
11
Reaction score
1
Points
3
I have a free hosting account. I am trying to send email from a php script. It does not work. I saw in a post that I need to upgrade php to get mail() to work. How do I do this?

$to = "xxxxxxxxx@cccccccc.net";
$subject = "This is a message sent from php";
$message = "to be or not to be that is the question";
$header = "bcc:ddddddddddddddd@pppppppp.net\r\n";
$mailsend = mail($to,$subject,$message,$header);

This is just a test message that is not working. are there any mail.ini files or other that have to be sent? This is my first try.
 
Top