php mail errors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
david_yg
Forum Newbie
Posts: 20
Joined: Tue Aug 09, 2011 10:19 am

php mail errors

Post by david_yg »

I have the following codes in send_mail.php

Code: Select all


<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Send Email</title>
</head>

<body>
		
	  <?php	 
      // send mail code
           
      $name=$_GET["name"];
      $email=$_GET["email"];
      $message=$_GET["message"];
      
      ?>
      
      
      Name	  :  <?php echo $name; ?><br>
      email   :  <?php echo $email;?><br>
      message :  <?php echo $message;?><br>
      
	  
      <?php
	  //$to = 'david_yg20@yahoo.com';
	  $to = 'garudamedia@localhost';
	  $subject = 'e-mail feedback';
	  
	  ini_set('sendmail_from', 'admin@localhost');
	  ini_set('SMTP', 'localhost');
	  //ini_set('SMTP', 'smtp.mail.yahoo.co.id');
	  //ini_set('smtp_port','25');
	  
	  $message2 = "Name	  : " + $name + "email   : " + $email + "message : " + $message;  
	  
	  mail($to, $subject, $message2);
	  ?>
      Telah di kirim!
      
      
      
    
      
</body>
</html>



It suppose to send me feedback message regarding my webpage to my garudamedia@localhost e-mail.

1. It did work accept that the message only give me "0" number, why is that? What is the correct syntax ?

2. I tried another option which is to send the feedback e-mail to my david_yg20@yahoo.com e-mail. Yet, I have not find the correct codes to send the feedback message to my yahoo mail. I keep receiving 503 yahoo mail error authentication (or something similars). What is the correct syntax to send my feedback e-mail to my yahoo mail ?

Thanks.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php mail errors

Post by social_experiment »

david_yg wrote:It did work accept that the message only give me "0" number, why is that? What is the correct syntax ?
The concatenation operator in php is the period (.)

Code: Select all

<?php
$message2 = "Name       : " + $name + "email   : " + $email + "message : " + $message;
// should be
$message2 = "Name : " . $name . " email : " . $email . " message: " . $message;
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
david_yg
Forum Newbie
Posts: 20
Joined: Tue Aug 09, 2011 10:19 am

Re: php mail errors

Post by david_yg »

What if I would like for each variable to be in different row. In html I would put <br>, how to do it in php ?

Thanks.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php mail errors

Post by social_experiment »

Code: Select all

<?php
$message2 = "Name : " . $name . " email : " . $email . " message: " . $message;
//
$message2 = "Name : " . $name . "<br />";
$message2 .= "Email : " . $email . "<br />";
$message2 .= "Message: " . $message;
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
david_yg
Forum Newbie
Posts: 20
Joined: Tue Aug 09, 2011 10:19 am

Re: php mail errors

Post by david_yg »

it does not work.

Here is the result:

[text]Name : David<br />Email : david_yg20@yahoo.com<br />Message: Ini cuma percobaan penulisan e-mail. Barangkali bisa memenuhi kebutuhan pemilik website.[/text]
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php mail errors

Post by Celauran »

If you're sending the email as plain text, use \n instead.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: php mail errors

Post by social_experiment »

Ah yeah, i somehow thought you were sending an html-type email.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: php mail errors

Post by phphelpme »

Code: Select all

$message2 = "Name: " . $name . "\n email: " . $email . "\n message: " . $message;
Or use \n\n for two line spaces.

Best wishes
User avatar
phazorRise
Forum Contributor
Posts: 134
Joined: Mon Dec 27, 2010 7:58 am

Re: php mail errors

Post by phazorRise »

use \n\n for two line spaces.
No.

See -
RFC 2821 standard for SMTP

To put new line separator in mail message body, it should be- CLRF ( "carriage return + line feed" ( "\r\n") ).

Also take look at -

http://en.wikipedia.org/wiki/Newline
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: php mail errors

Post by phphelpme »

lol you caught me out on a bad habbit there phazorrise... lol

Thanks for pointing that out and you are correct the RFC standard is \r\n although \n\n does accomplish the same end layout.

Thanks for pointing that out.

Best wishes
User avatar
phazorRise
Forum Contributor
Posts: 134
Joined: Mon Dec 27, 2010 7:58 am

Re: php mail errors

Post by phazorRise »

not using CRLF in headers might cause errors when using smtp specailly.
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: php mail errors

Post by phphelpme »

Yes I understand what you are refering to phaserrise but I think in this case the email is being sent as standard text not html. But you were right to correct me on the standards.

Best wishes
Post Reply