PHP Sendmail

Status
Not open for further replies.

memres25

New Member
Messages
3
Reaction score
0
Points
0
Hello. It seems that the below code doesn't send the mails.

$today = date('d.m.Y');
$now = date('H:i');
$ip = getenv('REMOTE_ADDR');
$agent = getenv('HTTP_USER_AGENT');
$referer = getenv('HTTP_REFERER');
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$to = "my@email.com";
$from = "From: $name <$email>";
$from2 = "From: Me <$to>";
$content = "Content for me";
$content2 = "Content for sender";
if ($email && $message)
mail($to, $subject, $content, $from); // to me
mail($email, $subject2, $content2, $from2); // to sender

I'll appreciate your help. Thanks.
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
From: must be a valid email account registered on your cPanel
 

stpvoice

Community Support Rep
Community Support
Messages
5,987
Reaction score
212
Points
63
Hello,

The content-type header must be present and set to text/plain for php mail to work. Here's a copy of a script I know to work on all free servers. Maybe you can adapt it to what you need:
Code:
<?php
$to  = 'them@example.com' . ', ';
$subject = 'Subject here';
$message = '
Enter message body
';
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\r\n";
$headers .= 'To: First Last <them@example.com>' . "\r\n";
$headers .= 'From: First Last <you@example.com>' . "\r\n";
if (mail($to,$subject,$message,$headers) ) {
       echo "email sent";
    } else {
       echo "email couldn't be sent";
};
?>

Also, you need to ensure any messages are sent from an address that actually exists in your cPanel.
 
Last edited:

memres25

New Member
Messages
3
Reaction score
0
Points
0
I use Google Apps for my domain's email accounts. Am I able to use sendmail via my Google email account?
 

memres25

New Member
Messages
3
Reaction score
0
Points
0
Thank you in advance for whom try to help me.

I solve the matter by changing the $to variable from my local email address to a remote one.
 
Status
Not open for further replies.
Top