Jump to content

help with using mail() to send a simple email


Gmunky

Recommended Posts

I have a form page that has a subject,message, and from text box.

I want to be able to send email once the submit button is clicked.

my code:

 

//if submit button is clicked, send email

if (isset($_POST['submit']))

{

$from=$_POST['from'];

$message=$_POST['message'];

$subject=$_POST['subject'];

 

//$to=$_POST['to'];

$to="[email protected]";

$date = date("F j, Y, g:i a");

$headers ="From: [email protected]";

 

 

   

if ( mail("$to","$subject","$message") )

{

echo "<font color=red>Your message has been sent to $to. Thank You!</font><br>";

}

else

echo "mail not sent";

 

}

 

 

The problem is I Keep getting this error below and I have no clue how to fix it!

 

ErrorCode: 2 ErrorMsg : mail() [function.mail]: Unable to send message to SMTP server. No recipients specified. ite. ice ready. mail not sent

I just tried it and it still doesn't work. I dont think that part of the code is the problem.

Even if i hardcode the values and use mail("[email protected]","hello","This is a test");

i still get this error:

ErrorCode: 2 ErrorMsg : mail() [function.mail]: Unable to send message to SMTP server. No recipients specified. ite. ice ready. mail not sent

 

 

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

 

note this:

 

Example 1050. Sending mail with extra headers.

 

The addition of basic headers, telling the MUA the From and Reply-To addresses:

<?php

$to      = '[email protected]';

$subject = 'the subject';

$message = 'hello';

$headers = 'From: [email protected]' . "\r\n" .

    'Reply-To: [email protected]' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

 

mail($to, $subject, $message, $headers);

?>

 

Example 1051. Sending mail with an additional command line parameter.

 

The additional_parameters parameter can be used to pass an additional parameter to the program configured to use when sending mail using the sendmail_path.

<?php

mail('[email protected]', 'the subject', 'the message', null,

  '[email protected]');

?>

My error went away but I still don't get an email.

I'm on an AS400/IBM platform

 

 

Is there something I need to change in the .ini file?

 

this is what mine looks like right now

 

[mail function]

 

 

 

 

SMTP = localhost

 

smtp_port = 25

 

 

 

 

 

sendmail_from = [email protected]

 

 

 

 

 

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").

 

 

 

 

sendmail_path =

 

 

 

 

 

; Force the addition of the specified parameters to be passed as extra parameter

 

 

 

 

; to the sendmail binary. These parameters will always replace the value of

 

 

 

 

; the 5th parameter to mail(), even in safe mode.

 

 

 

 

;mail.force_extra_parameters =

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.