Jump to content

[SOLVED] sending mail


sw45acp

Recommended Posts

hi,

im trying to send an email confirmation link to someone when they want to change their email address. when I include a link in the email, it does not send!

 

if (isset($_POST["change_email"]))
{
$token = $_POST["token"];

//generate unique id
$uid = md5(uniqid(rand(), true));
$sql = mysql_query("UPDATE admin SET `uid` = '$uid' WHERE `password` = '$token'");
if (!$sql)
{
	die('Could not execute query!: ' . mysql_error());
	mysql_close($con);
}
else
{
	mysql_close($con);
	$email = $_POST["email"];
	//compose email parts
	$subject = "MHS WTP Control Panel";
	$header = "You have changed your login email address for the control panel.";
	$message = "Please confirm this change by clicking the link below:\r\n";
	$message .= "https://mhswtpmanage.c6.ixwebhosting.com/cp_info.php?token=$token&uid=$uid";

                //if $message was "http://www.google.com/" it works, or if it was "bla sldjfalkdjf" it works.
                //but it doesnt work with that url. I don't think secure connections have anything to do with it

	ini_set('sendmail_from','[email protected]');
	$sentmail = mail($email,$subject,$message,$header);
	if (!$sentmail)
	{
		die('Could not send mail');
	}
	else
	{
		//continue on to next page
	}
}
}

 

maybe it is because the send mail function is too deep into the code, i dont know.

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/117601-solved-sending-mail/
Share on other sites

Try:

if (isset($_POST["change_email"]))
{
$token = $_POST["token"];

//generate unique id
$uid = md5(uniqid(rand(), true));
$sql = mysql_query("UPDATE admin SET `uid` = '$uid' WHERE `password` = '$token'");
if (!$sql)
{
	die('Could not execute query!: ' . mysql_error());
	mysql_close($con);
}
else
{
	mysql_close($con);
	$email = $_POST["email"];
	//compose email parts
	$subject = "MHS WTP Control Panel";
	$header = "You have changed your login email address for the control panel.";
	$message = "Please confirm this change by clicking the link below:\r\n";
	$message .= '<a href="https://mhswtpmanage.c6.ixwebhosting.com/">https://mhswtpmanage.c6.ixwebhosting.com/</a>';

                //if $message was "http://www.google.com/" it works, or if it was "bla sldjfalkdjf" it works.
                //but it doesnt work with that url. I don't think secure connections have anything to do with it

	ini_set('sendmail_from','[email protected]');
	$sentmail = mail($email,$subject,$message,$header);
	if (!$sentmail)
	{
		die('Could not send mail');
	}
	else
	{
		//continue on to next page
	}
}
}

Link to comment
https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604904
Share on other sites

commenting that out either doesn't work, because it doesn't send it at all

if (isset($_POST["change_email"]))

{

$token = $_POST["token"];

 

//generate unique id

$uid = md5(uniqid(rand(), true));

$sql = mysql_query("UPDATE admin SET `uid` = '$uid' WHERE `password` = '$token'");

if (!$sql)

{

die('Could not execute query!: ' . mysql_error());

mysql_close($con);

}

else

{

mysql_close($con);

$email = $_POST["email"];

//compose email parts

$subject = "MHS WTP Control Panel";

$headers= "You have changed your login email address for the control panel.";

$message = "Please confirm this change by clicking the link below:\r\n";

$message .= '<a href="https://mhswtpmanage.c6.ixwebhosting.com/">https://mhswtpmanage.c6.ixwebhosting.com/</a>';

 

//ini_set('sendmail_from','[email protected]');

$sentmail = mail($email,$subject,$message,$headers);

if (!$sentmail)

{

die('Could not send mail');

}

else

{

//continue on to next page

}

}

}

Link to comment
https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604919
Share on other sites

oh! sorry here is the source for this one

<?php
if (isset($_POST["submit"]))
{
$email = $_POST["email"];

//gather parts
$subject = "test";
$header = "more test";
$message = "even more test\r\n";
$message .= '<a href="http//www.google.com/">Google</a>';

ini_set('sendmail_from','[email protected]');
$sentmail = mail($email,$subject,$message,$header);
if (!$sentmail)
{
	echo "Could not send mail";
}
else
{
	echo "Sent mail, and the link does appear this time.<br />";
	echo $subject . "<br />" . $header . "<br />" . $message . "<br />";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604939
Share on other sites

OK.  Try this:

 

if (isset($_POST["change_email"]))
{
   $token = $_POST["token"];
   
   //generate unique id
   $uid = md5(uniqid(rand(), true));
   $sql = mysql_query("UPDATE admin SET `uid` = '$uid' WHERE `password` = '$token'");
   if (!$sql)
   {
      die('Could not execute query!: ' . mysql_error());
      mysql_close($con);
   }
}//end of if(isset($_POST["change_email"]))
else
{
      $email = $_POST["email"];
      //compose email parts
      $subject = "MHS WTP Control Panel";
      $headers = 'From: [email protected]';
      $message = "Please confirm this change by clicking the link below:\r\n";
      $message .= 'https://mhswtpmanage.c6.ixwebhosting.com/';
      
      //ini_set('sendmail_from','[email protected]');
      $sentmail = mail($email,$subject,$message,$headers);
      if (!$sentmail)
      {
         die('Could not send mail');
      }
      else
      {
         //continue on to next page
      }
}//end of else


Link to comment
https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604951
Share on other sites

no luck man. I also tried reducing it just down to this:

if (isset($_POST["change_email"]))
{

$email = $_POST["email"];
//compose email parts
$subject = "MHS WTP Control Panel";
$headers = "You have changed your login email address for the control panel.";
$message = "Please confirm this change by clicking the link below:\r\n";
$message .= '<a href="https://mhswtpmanage.c6.ixwebhosting.com/">https://mhswtpmanage.c6.ixwebhosting.com/cp_info.php</a>';

//ini_set('sendmail_from','[email protected]');
        //doesnt work whether I have ini_set in there or not


$sentmail = mail($email,$subject,$message,$headers);
if (!$sentmail)
{
	die('Could not send mail');
}
else
{
	echo "all good";
}
}

 

Link to comment
https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604966
Share on other sites

ive reduced it down further to this, and removed the outside if() condition

no success yet

<?php

<?php
$email = $_POST["email"];
//compose email parts
$subject = "MHS WTP Control Panel";
$message = "Please confirm this change by clicking the link below:\r\n";
$message .= '<a href="https://mhswtpmanage.c6.ixwebhosting.com/">https://mhswtpmanage.c6.ixwebhosting.com/cp_info.php</a>';

ini_set('sendmail_from','[email protected]');
$sentmail = mail($email,$subject,$message);
if (!$sentmail)
{
die('Could not send mail');
}
else
{
echo "all good";
}
?>

?>

Link to comment
https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604980
Share on other sites

positive that $email is not empty. I think maybe something is wrong w/ the server. Because even this simple page doesnt do it.

<?php
if (isset($_POST["submit"]))
{
$email = $_POST["email"];
//compose email parts
$subject = "MHS WTP Control Panel";
$message = "Please confirm this change by clicking the link below:\r\n";
$message .= '<a href="https://mhswtpmanage.c6.ixwebhosting.com/cp_info.php">https://mhswtpmanage.c6.ixwebhosting.com/cp_info.php</a>';

ini_set('sendmail_from','[email protected]');
$sentmail = mail($email,$subject,$message);
if (!$sentmail)
{
die('Could not send mail');
}
else
{
echo "all good" . "<br />";
}
}
?>
<html>
<head>
</head>
<body>
<form action="test2.php" method="post">
Enter email:<br />
<input type="text" name="email" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604991
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.