Jump to content

I have been trying all day to create a reset password script for my game and i cant get it to sent any mail. I ether get no email at all with no problems with php code or i get a mail failure email saying that there's no recipient.

I am a beginner with PHP 5.4 and most of the time i have no idea what i'm doing.

 

here's a snippet of the mail code:

...
...
$to=$_GET['email'];

$mail = Mail::factory('Mail');

$head['To'] = $to;
$head['From'] = "MyEmail";
$head['Subject'] = "Test Mail";
$body = "This is a test!";
$sent = $mail->send($to, $head, $body);

if($sent = 1){
    echo "We have sent the password reset link to your email: <b>".$to."</b>";
}
if ($sent = 0){
    echo "There was a problem sending the email, Please contact support for help"; mail_error();
}
...
...

I have checked and $to is the to email i want to send to

Link to comment
https://linustechtips.com/topic/761504-php-sending-mail-not-being-sent/
Share on other sites

Link to post
Share on other sites

2 minutes ago, Dutch-stoner said:

Is the mail function working on the webserver you are using? Does the webserver have propper settings for an SMTP server? Can you send any other e-mails when using stock/tutorial mail scripts?

the mail() i tried before doesn't work or i'm getting it wrong.

Link to post
Share on other sites

12 minutes ago, Dutch-stoner said:

If the mail() function doesn't work, your webserver is most likely now set-up to send outgoing mail. Check your webserver manual on how to set up the PHP mail() function.

ah found the problem. It appears that i can only send emails to other accounts using the same domain. how would i fix this?

Link to post
Share on other sites

4 hours ago, TheGamingHD said:

 


if($sent = 1){
	echo "We have sent the password reset link to your email: <b>".$to."</b>";
}
if ($sent = 0){
	echo "There was a problem sending the email, Please contact support for help"; mail_error();
}
		

 

This won't work, because you are assigning 1 to $sent rather than actually testing the return value. The return value of the PEAR mailer, which it looks like you're using, is TRUE on success, or PEAR_Error on failure ([docs]). It is successful if $sent is equal to true (which you should test using a triple equals sign), and otherwise the error message is stored in $sent->getMessage().

if($sent === true){
	echo "We have sent the password reset link to your email: <b>".$to."</b>";
} else {
	echo "There was a problem sending the email, Please contact support for help";
	echo $sent->getMessage(); // optional
}

 

Also, you said in your original post that you are using PHP 5.4. PHP 5.4 has been unsupported, even for security issues, for 1 year and 7 months, and PHP 5.5 is also unsupported

. Your code should still work with all versions of PHP that have been released since then, so I would encourage you to switch to a more up to date version if at all possible (ideally 7.1).

HTTP/2 203

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×