PHP Send Mail

Status
Not open for further replies.

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
368
Points
83
Hi,

What headers are you sending the emails with? (the fourth parameter)

Thank you,
 

sandy.beach

Member
Prime Account
Messages
95
Reaction score
0
Points
6
I have tried this script as well as a couple of others, i know a few weeks ago i had a mail script which i was experimenting with and i was curious if that flagging your system as an alert and because of that the mail system on my account had been disabled?

$to = 'sandy.beach.it@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: sandy.beach.it@gmail.com' . "\r\n" .
'Reply-To: sandy.beach.it@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

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

echo "mail sent";
 

sandy.beach

Member
Prime Account
Messages
95
Reaction score
0
Points
6
as well as this:

$to = 'sandy.beach.it@gmail.com';
$subject = 'the subject';
$message = 'hello';
$header = "From: noreply@example.com\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/plain; charset=utf-8\r\n";
$header.= "X-Priority: 1\r\n";

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

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
368
Points
83
As far as I am aware, our mail system will only allow the "From" header to be an email address that is listed in your "Email Accounts" in cPanel (for security reasons). Could you please try doing this?

Thank you,
 

sandy.beach

Member
Prime Account
Messages
95
Reaction score
0
Points
6
Just to clarify the X10 email address i have is: david.beach@sandybeachit.x10.mx this is listed in my email accounts and is live.

I have amended the script to be the following:
http://sandybeachit.x10.mx/hosting/findibuzz/phpinfo.php
But unfortunately this has not worked and no emails are still coming through.

Is it possible to check my account please just to make sure there is nothing disabled / blocked etc?

Thanks

-----------------

$boundary=md5(uniqid(rand()));
$header .= "From:Name<david.beach@sandybeachit.x10.mx>\n";
$header .= "Reply-To:Name <david.beach@sandybeachit.x10.mx> \n";
$header .= 'MIME-Version: 1.0'."\r\n";
$header .= "Content-type: multipart/alternative;boundary=$boundary\n";

$adres = "sandy.beach.it@gmail.com";

$subject = "subject";

$message = "This is multipart message using MIME\n";
$message .= "--" . $boundary . "\n";
$message .= "Content-type: text/plain;charset=iso-8859-1\n";
$message .= "Content-Transfer-Encoding: 7bit". "\n\n";
$message .= "Plain text version\n\n";
$message .="--" . $boundary . "\n";
$message .="Content-type: text/html;charset=iso-8859-1\n";
$message .= "Content-Transfer-Encoding: 7bit". "\n\n";
$message .="<html>
<body>
<center>
<b>HTML text version</b>
</center>
</body>
</html>\n\n";
$message .= "--" . $boundary . "--";

if(mail($adres, $subject, $message, $header))
{
print'message sent';
}
else
{
print'message was not sent';
}
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
I believe that the header should end with a blank line.
 

David Beach

New Member
Messages
17
Reaction score
0
Points
1
I believe that the header should end with a blank line.

Ok i can understand that but this was the original code i was using which was working but now does not work. There are no error messages generated and nothing had changed in the code.



$host = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);

//send email
$to = "$email";
$subject = "Account Details Recovery";
$body = "Here are your new password details:\n
User Email: $email \n
Password: $password

Thank You

Administrator
$host_upper
______________________________________________________
THIS IS AN AUTOMATED RESPONSE
***DO NOT RESPOND TO THIS EMAIL****

***MAIL WILL NOT BE RECEIVED AT THE ABOVE ADDRESS***
";



$additionalheaders = "From: \"Member Registration\" <no-reply@$host>";
$additionalheaders .= "Reply-To: \"Member Registration\" <no-reply@$host>";
mail($to, $subject, $body, $additionalheaders);
 

sandy.beach

Member
Prime Account
Messages
95
Reaction score
0
Points
6
Ok just to be clear i stupidly didnt realise i had two accounts on this forum - hence the two avatars which are the same, i didnt even realise until now i was using a different account so i apologise if i have caused confusion and will only be using this one from now one which is what i should be using!

Thanks

All previous posts were from me - I am David Beach
 

Carolyn Reede

New Member
Messages
1
Reaction score
0
Points
1
Using mail() is hard to get right and I'm pretty sure the PHP devs don't intend for it to be called directly. I use a PHP email library called Ultimate Email Toolkit, but there are others like PHP Mailer, Swift Mailer, etc. I recommend using one of those. Some mail hosts do block the mail() function but PHP will emit an error.

As a side note, your code possibly has a security vulnerability in it: You aren't sanitizing inputs. For example, $_SERVER["HTTP_..."] vars are able to be spoofed by a client. A good email library will properly sanitize areas of potential user input for you.
 

sandy.beach

Member
Prime Account
Messages
95
Reaction score
0
Points
6
I do understand that,
Using mail() is hard to get right and I'm pretty sure the PHP devs don't intend for it to be called directly. I use a PHP email library called Ultimate Email Toolkit, but there are others like PHP Mailer, Swift Mailer, etc. I recommend using one of those. Some mail hosts do block the mail() function but PHP will emit an error.

As a side note, your code possibly has a security vulnerability in it: You aren't sanitizing inputs. For example, $_SERVER["HTTP_..."] vars are able to be spoofed by a client. A good email library will properly sanitize areas of potential user input for you.

Thanks Carolyn i do understand this, but this is not what i am asking, i have scripts which were working perfectly fine and now they are not, when i have not made any changes to the code which indicates something has changed on the backend hence my query.

You do not need PHP Mailer etc to directly send an email, but they can be very useful and make things simpler, i just am doing things differently hence my query if anyting had changed on the backed
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Does no-reply exist on your domain? You're not allowed to spoof the From header, and the address used must correspond to an email account that exists on your hosting account. (The idea is to prevent phishing.)
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
Just to clarify the X10 email address i have is: david.beach@sandybeachit.x10.mx this is listed in my email accounts and is live.
I made a copy of your code in post #6 (above) - and changed as shown below
My free-hosting account is on [ xo3 = (old Level) - IP: 198.91.81.3 ]
other members of my computer club tested this script on the other two (2) free-hosting servers
we had no issues with it - and I received the Emails from - all three (3) free-hosting servers - in my Gmail account

PHP:
<?php
// added this next line
error_reporting(E_ALL);

$boundary=md5(uniqid(rand()));

//$header .= "From:Name<david.beach@sandybeachit.x10.mx>\n";
//$header .= "Reply-To:Name <david.beach@sandybeachit.x10.mx> \n";
// replaced [ .= ] with [ = ] in this next line
$header = "From:Name<(Email address in my account)>\n";
$header .= "Reply-To:Name <(Email address in my account)> \n";

$header .= 'MIME-Version: 1.0'."\r\n";
$header .= "Content-type: multipart/alternative;boundary=$boundary\n";

//$adres = "sandy.beach.it@gmail.com";
$adres = "(my Gmail address)";

$subject = "subject";

$message = "This is multipart message using MIME\n";
$message .= "--" . $boundary . "\n";
$message .= "Content-type: text/plain;charset=iso-8859-1\n";
$message .= "Content-Transfer-Encoding: 7bit". "\n\n";
$message .= "Plain text version\n\n";
$message .="--" . $boundary . "\n";
$message .="Content-type: text/html;charset=iso-8859-1\n";
$message .= "Content-Transfer-Encoding: 7bit". "\n\n";

$message .="<html>
<body>
<center>
<b>HTML text version</b>
</center>
</body>
</html>\n\n";
$message .= "--" . $boundary . "--";

if(mail($adres, $subject, $message, $header))
{
print'message sent';
}
else
{
print'message was not sent';
}
?>
 

sandy.beach

Member
Prime Account
Messages
95
Reaction score
0
Points
6
Does no-reply exist on your domain? You're not allowed to spoof the From header, and the address used must correspond to an email account that exists on your hosting account. (The idea is to prevent phishing.)

In my script i was not using a "no reply" email address.

I was using david.beach@sandybeachit.x10.mx as the from address.

As a side note i can email to "david.beach@sandybeachit.x10.mx" from my gmail account which comes through straight away but if i send an email from ths account (david.beach@sandybeachit.x10.mx) to my gmail account the email does not come through and yes i have waited about an hour for the email to appear in my gmail account and it is not in my inbox, spam folder or anywhere else yet i was able to receive emails (at david.beach@sandybeachit.x10.mx) very promptly.

So it looks like out going email on my account has been restricted, can someone take a look at the backend please and see what limitations have been put in place?

Thanks
 

sandy.beach

Member
Prime Account
Messages
95
Reaction score
0
Points
6
I made a copy of your code in post #6 (above) - and changed as shown below
My free-hosting account is on [ xo3 = (old Level) - IP: 198.91.81.3 ]
other members of my computer club tested this script on the other two (2) free-hosting servers
we had no issues with it - and I received the Emails from - all three (3) free-hosting servers - in my Gmail account

Thanks for confirming this issue is not my code, i really appreciate the time you and your friends have taken in testing this, please pass on my thanks to them.
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
Hi David, please test your mail script again and let us know the result. I believe that I've located the problem and that it is now corrected.
 

sandy.beach

Member
Prime Account
Messages
95
Reaction score
0
Points
6
Awesome i did some testing of a couple of scripts and it is all working now, thanks Bryon what was the cause ?
 
Status
Not open for further replies.
Top