Page 1 of 1

Php e-mail errors

Posted: Tue Aug 09, 2011 10:34 am
by david_yg
Hello,

I am trying to write codes to accept feedback form, which suppose to send the message to my e-mail address. The following is the action codes (send_mail.php) form after you press submit:

Code: Select all


<title>Send Email</title>
</head>

<body>

    // send mail code
      $nama=$_GET["nama"];
      $email=$_GET["email"];
      $message=$_GET["message"];
      
      // akhir hapus blok
      Nama	  :  <?echo $nama;?><br>
      email   :  <?echo $email;?><br>
      message :  <?echo $message;?><br>
      
      <?
	  ini_set("SMTP", "172.16.1.1");
	  ini_set("sendmail_from", "$nama");
	  mail("$nama", "$email", "$message");
	  ?>
      Telah di kirim!
      
      
      
    
      
</body>
</html>



The following errors appears :

// send mail code $nama=$_GET["nama"]; $email=$_GET["email"]; $message=$_GET["message"]; // akhir hapus blok Nama :
Notice: Undefined variable: nama in C:\xampp\htdocs\webproject\send_email.php on line 16

email :
Notice: Undefined variable: email in C:\xampp\htdocs\webproject\send_email.php on line 17

message :
Notice: Undefined variable: message in C:\xampp\htdocs\webproject\send_email.php on line 18


Notice: Undefined variable: nama in C:\xampp\htdocs\webproject\send_email.php on line 22

Notice: Undefined variable: nama in C:\xampp\htdocs\webproject\send_email.php on line 23

Notice: Undefined variable: email in C:\xampp\htdocs\webproject\send_email.php on line 23

Notice: Undefined variable: message in C:\xampp\htdocs\webproject\send_email.php on line 23

Warning: mail() [function.mail]: Failed to connect to mailserver at "172.16.1.1" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\webproject\send_email.php on line 23
Telah di kirim!

What might be the problem?

Please help. thanks.

Re: Php e-mail errors

Posted: Tue Aug 09, 2011 11:32 am
by Celauran
You're missing opening and closing PHP tags when you're assigning values to the variables, which is why you're getting the undefined variable notices. As for the SMTP warning, it's not particularly verbose so it's hard to say. Does the SMTP server require authentication?

Re: Php e-mail errors

Posted: Wed Aug 10, 2011 2:51 am
by david_yg
I wonder why. I already put <?php ?> in front of the question mark, but it still does not remove the errors.

Code: Select all

<title>Send Email</title>
</head>

<body>

      // send mail code
      $nama=$_GET["nama"];
      $email=$_GET["email"];
      $message=$_GET["message"];
      
      // akhir hapus blok
      Nama	  :  <?php echo $nama;?><br>
      email   :  <?php echo $email;?><br>
      message :  <?php echo $message;?><br>
      
      <?php
	  ini_set("SMTP", "172.16.1.1");
	  ini_set("sendmail_from", "$nama");
	  mail("$nama", "$email", "$message");
	  ?>
      Telah di kirim!
      
      
      
    
      
</body>
</html>

The errors still remains.

Regarding the SMTP server, I do not whether it requires authentication or not. How to check it? I set my website by using localhost, xampp. I have a software called Argosoft Mail server, do I need to use it?

Thanks.

Re: Php e-mail errors

Posted: Wed Aug 10, 2011 4:10 am
by Dodon
What he meant was

Code: Select all

<?php
       $nama=$_GET["nama"];
       $email=$_GET["email"];
       $message=$_GET["message"];
 ?>      
You declare a variable and assign a value to it in PHP, at the moment you probably get those line on your HTML page.

Re: Php e-mail errors

Posted: Wed Aug 10, 2011 4:48 am
by david_yg
I get those fixed up. Now this is the new errors:

Name : david
email : david_yg20@yahoo.com
message : message

Warning: mail() [function.mail]: Failed to connect to mailserver at "172.16.1.1" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\webproject\send_email.php on line 28
Telah di kirim!


My point is I would like the feedback form information being sent to david_yg20@yahoo.com. Any ideas what's the code? Thx.

Re: Php e-mail errors

Posted: Wed Aug 10, 2011 5:16 am
by Dodon
Well,

Is the server installed at 172.16.1.1 port 25?
Does it require authentication?
Is the mail server running?
Is 172.16.1.1 even the right address?

Re: Php e-mail errors

Posted: Thu Aug 11, 2011 10:43 am
by david_yg
the xampp and Argsoft mail server server is installed at localhost port 25 (mail server).
I do not know whether it requires authentication or not. The mail server is running.

I modify the codes into:

Code: Select all

  

   <?php
             ini_set("SMTP", "localhost");
             ini_set("admin@localhost", "$name");
             mail("$name", "$email", "$message");
    ?>
    Telah di kirim!


New errors:

Name : david
email : david_yg20@yahoo.com
message : message

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\webproject\send_email.php on line 28
Telah di kirim!

What should I do?

Re: Php e-mail errors

Posted: Thu Aug 11, 2011 11:16 am
by Celauran
david_yg wrote: I modify the codes into:

Code: Select all

ini_set("admin@localhost", "$name");
That's not going to work. admin@localhost isn't a valid parameter. Based on the error, sendmail_from is a required setting. What I imagine you were trying to accomplish is this:

Code: Select all

ini_set('sendmail_from', 'admin@localhost');

Re: Php e-mail errors

Posted: Thu Aug 11, 2011 12:12 pm
by david_yg
I modify the codes into:

Code: Select all

		
	  <?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
	  ini_set('SMTP', 'localhost');
	  ini_set('sendmail_from', 'admin@localhost');
	  mail('$name', '$email', '$message');
	  ?>
      Telah di kirim!
The new errors:

Name : david
email : david_yg@yahoo.com
message : message

Warning: mail() [function.mail]: SMTP server response: 554 User unknown in C:\xampp\htdocs\webproject\send_email.php on line 28
Telah di kirim!

Line 28 is: mail('$name', '$email', '$message');

How to fix the errors ?

Re: Php e-mail errors

Posted: Thu Aug 11, 2011 12:46 pm
by Dodon
You're not using the mail function properly

http://php.net/manual/en/function.mail.php

Code: Select all

mail($email,"Subject",$message);
[/php]

Re: Php e-mail errors

Posted: Thu Aug 11, 2011 12:49 pm
by Celauran
Also, variable substitution will not occur inside single quotes.

Re: Php e-mail errors

Posted: Fri Aug 12, 2011 6:30 am
by david_yg
I have tried to modify the code to:

Code: Select all

<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';
	  $subject = 'e-mail feedback';
	  ini_set('SMTP', 'smtp.mail.yahoo.co.id');
                  ini_set('smtp_port','25');
	  ini_set('sendmail_from', 'admin@localhost');
	  mail($to, $subject, $message);
	  ?>
      Telah di kirim!
      
      
      
The following errors appears:

Name : David
email : david_yg20@yahoo.com
message : message

SMTP server response: 530 authentication required - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html in C:\xampp\htdocs\webproject\send_email.php on line 31
Telah di kirim!

I also would like the whole things (name, e-mail, and message) to be included in my feedback e-mail. It slightly works earlier when I set up my smtp to localhost, to the point that it only send me the message excluding name and e-mail. Now it does not work at all after I change my SMTP to smtp.mail.yahoo.co.id

Can anyone help me fix this prob ?

How to authenticate smtp server ?