Can't send email in using php

Status
Not open for further replies.

jerome1g

Member
Messages
113
Reaction score
1
Points
18
Not sure if I am do this right. I have programs on X10hosting that I would like to be able to send email from my php to my gmail account. When I run the email program I get nothing. I do get the echo message at the end of the program
Thanks

Here is the program:

<?php
$to = 'XXXXXXX@gmail.com';
$subject = 'the subject';
$message = 'hello is there anybody out there?';
$headers = 'From: XXXXXX@gmail.com' . "\r\n" .
'Reply-To: XXXXXX@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
echo 'And away we go'
?>
 

jerome1g

Member
Messages
113
Reaction score
1
Points
18
Script looks like this now

<?php
$to = 'jperson19468@gmail.com';
$subject = 'the subject';
$message = 'hello is there anybody out there?';
$headers = 'From: jperson19468@gmail.com' . "\r\n" .
'Reply-To: jperson19468@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

$success = mail($to, $subject, $message, $headers);
if (!$success) {
$errorMessage = error_get_last()['message'];
}else{
echo 'And away we go';
}
?>
 

Anna

I am just me
Staff member
Messages
11,739
Reaction score
579
Points
113
The from address must be one that is present in your account, in other words an email address that you created under your domain.
What you are attempting with your script would be called spoofing (pretending to be a sender you are not, gmail in this case), and this is not allowed and would be stoped by our spam filters on outgoing mail server.
 

jerome1g

Member
Messages
113
Reaction score
1
Points
18
You are correct. When I change the from address to an email address under my account it worked.
My script looks like this now

<?php
$to = 'XXXXXX@gmail.com';
$subject = 'the subject';
$message = 'hello is there anybody out there?';
$headers = 'From: anyname@YYYYYYY.x10host.com' . "\r\n" .
'Reply-To: XXXXXXX@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

$success = mail($to, $subject, $message, $headers);
if (!$success) {
$errorMessage = error_get_last()['message'];
}else{
echo 'And away we go';
}
?>

Thank You:)
 
Status
Not open for further replies.
Top