mail function

hi guys,
I’m pretty new in PHP and I’m trying to make a form that sends emails with data entered.
I can see the confirmation page but no emails are being sent. Can you tell me what needs to be done to send emails when the form is completed?

here is the php code:
[php]<?php
$name = $_POST[‘firstname’].’ '.$_POST[‘lastname’];
$email = $_POST[‘email’];
$subject = ‘PHP Form’;
$msg = “Name: $name”;

$retval = mail('[email protected]', $subject, $msg, 'From:' . $email);
if( $retval == true ) {
	echo "Message sent successfully...";
} else {
	echo "Message could not be sent...";
}
echo 'Hello ' . $name;

?>[/php]

And here is how the mail function looks in my php.ini file:

[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 25

; For Win32 only.
;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 parameters
; 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 =

Thank you.

You need to include headers, that’s where the From goes.

Wrap it in a try catch statement and echo out the error. We can guess all we want, you can get the information you need.

The mail function isn’t being used right, that’s why its not going.
[php] <?php
$name = $_POST[‘firstname’].’ '.$_POST[‘lastname’];
$email = $_POST[‘email’];
$subject = ‘PHP Form’;
$msg = “Name: $name”;

$headers = "From: " . strip_tags($_POST[‘email’]) . “\r\n”;
$headers .= "Reply-To: ". strip_tags($_POST[‘email’]) . “\r\n”;

// email(to, subject, message, headers)
$retval = mail(‘[email protected]’, $subject, $msg, $headers);

if($retval) {
echo “Message sent successfully…”;
} else {
echo “Message could not be sent…”;
}

echo 'Hello ’ . $name;
?>[/php]
That should work.

Sponsor our Newsletter | Privacy Policy | Terms of Service