sw45acp Posted July 31, 2008 Share Posted July 31, 2008 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 More sharing options...
papaface Posted July 31, 2008 Share Posted July 31, 2008 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 More sharing options...
sw45acp Posted July 31, 2008 Author Share Posted July 31, 2008 no luck Link to comment https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604908 Share on other sites More sharing options...
ainoy31 Posted July 31, 2008 Share Posted July 31, 2008 change the $header to $headers = '[email protected]'; and comment out //ini_set('sendmail_from','[email protected]'); Link to comment https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604915 Share on other sites More sharing options...
sw45acp Posted July 31, 2008 Author Share Posted July 31, 2008 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 More sharing options...
sw45acp Posted July 31, 2008 Author Share Posted July 31, 2008 maybe the php.ini file isnt set up right, but I dont have access to it, so thats why I've always used ini_set() Link to comment https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604922 Share on other sites More sharing options...
ainoy31 Posted July 31, 2008 Share Posted July 31, 2008 did it work? Link to comment https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604926 Share on other sites More sharing options...
sw45acp Posted July 31, 2008 Author Share Posted July 31, 2008 no it didnt work again. bu here is a simple one I just built... and this one works: http://mhswtpmanage.c6.ixwebhosting.com/test.php i dont under stand what the difference is Link to comment https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604934 Share on other sites More sharing options...
sw45acp Posted July 31, 2008 Author Share Posted July 31, 2008 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 More sharing options...
ainoy31 Posted July 31, 2008 Share Posted July 31, 2008 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 More sharing options...
sw45acp Posted July 31, 2008 Author Share Posted July 31, 2008 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 More sharing options...
ainoy31 Posted July 31, 2008 Share Posted July 31, 2008 get rid of the headers all together and try. also, remove the if() condition and try. Link to comment https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604969 Share on other sites More sharing options...
sw45acp Posted July 31, 2008 Author Share Posted July 31, 2008 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 More sharing options...
ainoy31 Posted July 31, 2008 Share Posted July 31, 2008 you have checked to make sure $email is not empty? maybe just run this page by giving it a static email address like $to = ' your email here'; Link to comment https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604987 Share on other sites More sharing options...
sw45acp Posted July 31, 2008 Author Share Posted July 31, 2008 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 More sharing options...
ainoy31 Posted July 31, 2008 Share Posted July 31, 2008 Yeah. check with the hosting people and see how they are configuring the php settings to send out emails. Link to comment https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-604996 Share on other sites More sharing options...
sw45acp Posted July 31, 2008 Author Share Posted July 31, 2008 alright! well, thank you for all of your help. I really appreciate it. Link to comment https://forums.phpfreaks.com/topic/117601-solved-sending-mail/#findComment-605000 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.