0

I am trying to make a registration form and after submitting it will send a confirmation link for verification. I am using the php mail function. It echo's that the mail has been sent but after waiting for several minutes no email has been sent. I config my localhost to localhost:8080 and been using 3307 for my database and everything's fine because it feed in my database. My problem is that no email is sent. Can you tell me what is wrong or what i need to do to make this work because im just a beginner. Thanks:)

Here is my code:

<?php

include('config.php');

// table name 
$tbl_name='temp_members_db';

// Random confirmation code 
$confirm_code=md5(uniqid(rand())); 

// values sent from form 
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$pword=$_POST['pword'];
$number=$_POST['number'];
$house=$_POST['house'];
$street=$_POST['street'];
$city=$_POST['city'];

// Insert data into database 
$sql="INSERT INTO $tbl_name(confirm_code, firstname, lastname, email, password, number, house1, street1, city)VALUES('$confirm_code', '$firstname', '$lastname', '$email', '$pword', '$number', '$house', '$street', '$city')";
$result=mysql_query($sql);

// if suceesfully inserted data into database, send confirmation link to email 
if($result){
// ---------------- SEND MAIL FORM ----------------

// send e-mail to ...
$to=$email;

// Your subject
$subject="Your confirmation link here";

// From
$header="from: Athan Motorcycles <nickcuenza@gmail.com>";

// Your message
$message="Your Confirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.yourweb.com/confirmation.php?passkey=$confirm_code";

// send email
$sentmail = mail($to,$subject,$message,$header);
}

// if not found 
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>

so the messages from the POP3 said that

Connection from 127.0.0.1, Sat Dec 14 01:58:22 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 01:58:23 2013
Connection from 127.0.0.1, Sat Dec 14 01:58:54 2013
Connection from 127.0.0.1, Sat Dec 14 01:59:08 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 01:59:09 2013
Connection from 127.0.0.1, Sat Dec 14 01:59:40 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 01:59:41 2013
Connection from 127.0.0.1, Sat Dec 14 02:00:12 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 02:00:13 2013
Connection from 127.0.0.1, Sat Dec 14 02:00:44 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 02:00:45 2013
Connection from 127.0.0.1, Sat Dec 14 02:01:16 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 02:01:17 2013
Connection from 127.0.0.1, Sat Dec 14 02:01:48 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 02:01:49 2013
Connection from 127.0.0.1, Sat Dec 14 02:02:20 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 02:02:21 2013
Connection from 127.0.0.1, Sat Dec 14 02:02:52 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 02:02:53 2013
Connection from 127.0.0.1, Sat Dec 14 02:03:24 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 02:03:25 2013
Connection from 127.0.0.1, Sat Dec 14 02:03:56 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 02:03:57 2013
Connection from 127.0.0.1, Sat Dec 14 02:04:28 2013
User root, (2) 0 messages, 0 bytes
1 sec. elapsed, connection closed Sat Dec 14 02:04:29 2013

after checking the session it said that

01:59:08.609: Connection from 127.0.0.1, Sat Dec 14 01:59:08 2013
01:59:08.609: << +OK <6495609.23560@localhost>, POP3 server ready.<cr><lf>
01:59:09.593: >> USER root<cr><lf>
01:59:09.593: << +OK root is known here.<cr><lf>
01:59:09.593: >> PASS root<cr><lf>
01:59:09.593: << +OK Welcome! 0 messages (0 bytes)<cr><lf>
01:59:09.593: >> STAT<cr><lf>
01:59:09.593: << +OK 0 0<cr><lf>
01:59:09.593: >> QUIT<cr><lf>
01:59:09.593: << +OK localhost Server closing down.<cr><lf>
01:59:09.593: --- Connection closed normally at Sat Dec 14 01:59:09 2013. ---
01:59:09.593:
  • Does the page say that the email has been sent? What happens if you hard-code your own email address in there - does it work then? How about if you strip out everything that isn't required, like the header, and try it then? – andrewsi Dec 13 '13 at 16:50
  • 1
    **Warning:** you're using [a **deprecated** database API](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) yourself from. – Marcel Korpel Dec 13 '13 at 16:50
  • basic debugging: check the `mail()` return value for boolean FALSE (failure). Check your local mail server's logs to see what happened if/when PHP has handed over the email. Check the receiving server's mail logs and/or spam folders. – Marc B Dec 13 '13 at 16:51
  • Do you have a mailserver on the system? If it's a linux try installing postfix - sudo apt-get install postfix or sudo yum install postfix ? – benlumley Dec 13 '13 at 16:51
  • Besides, there's something wrong with your logic: `$sentmail` is only set when the INSERT query successfully completed, in the `else` block there's no `$sentmail`. – Marcel Korpel Dec 13 '13 at 16:52
  • yes the page say that the email has been send. I tried to strip/comment out the headers like what you said sir but still no luck. So what should i do sir @andrewsi? – user3088818 Dec 13 '13 at 16:55
  • ok so in my XAMPP/mailoutput folder there are text document and those are the messages that need to be sent. It receives everything sir @MarcB but I cant find the sent mail in my yahoo even in spam. – user3088818 Dec 13 '13 at 16:58
  • @user3088818 - are you sure that the mailserver is installed and running? – andrewsi Dec 13 '13 at 17:05
  • Sir @benlumley i am using XAMPP and i have this Mercury/32. If i want to use it should i configure my php.ini and use smtp port 25? – user3088818 Dec 13 '13 at 17:06
  • Sir @andrewsi i am using XAMPP and i started the Mercury and the ports running are 25,79,105,106,110,143,224 and i change my localhost:8080 to localhost only with 3307 to 3306. It just says the confirmation send and it feeds in the mailoutput folder of my XAMPP but still no interaction with the email address i inputted : – user3088818 Dec 13 '13 at 17:13
  • @user3088818 - check Mercury's logfiles, in that case, and make sure that it's receiving the emails. It should tell you exactly what the problem is. – andrewsi Dec 13 '13 at 17:14
  • Sir @andrewsi nothing is showing up when i execute the LOGS in Mercury it just say "Executing "d:\xampp\MercuryMail\LOGS" but nothing is showing up. I already commented out the SMTP = localhost smtp_port = 25 in php.ini because it says that comment it out when you use Mercury – user3088818 Dec 13 '13 at 17:25
  • @user3088818 - You need to open up the log files in a text editor. You don't need to execute them - they should be text files. – andrewsi Dec 13 '13 at 17:27
  • there is no logfiles in MercuryMail folder sir ? – user3088818 Dec 13 '13 at 17:32
  • Have a look at http://community.pmail.com/forums/thread/38162.aspx to make sure you've got logging turned on – andrewsi Dec 13 '13 at 17:35
  • Sir @andrewsi TCP0000 said **01:59:08.609: Connection from 127.0.0.1, Sat Dec 14 01:59:08 2013 01:59:08.609: << +OK <6495609.23560@localhost>, POP3 server ready. 01:59:09.593: >> USER root 01:59:09.593: << +OK root is known here. 01:59:09.593: >> PASS root 01:59:09.593: << +OK Welcome! 0 messages (0 bytes) 01:59:09.593: >> STAT 01:59:09.593: << +OK 0 0 01:59:09.593: >> QUIT 01:59:09.593: << +OK localhost Server closing down. 01:59:09.593: --- Connection closed normally at Sat Dec 14 01:59:09 2013. --- 01:59:09.593: ** – user3088818 Dec 13 '13 at 17:53
  • The other log said **Connection from 127.0.0.1, Sat Dec 14 02:00:44 2013 User root, (2) 0 messages, 0 bytes 1 sec. elapsed, connection closed Sat Dec 14 02:00:45 2013 ** – user3088818 Dec 13 '13 at 17:54
  • @user3088818 - that seems to be the logfile from a POP3 session, though - that's what yuo use when you're getting emails, not sending them. (Also, it'd be easier to read if you edit those into your question) – andrewsi Dec 13 '13 at 17:55
  • There sir @andrewsi i already edited the question:) – user3088818 Dec 13 '13 at 17:59
  • @user3088818 - I'm afraid that that's not the right log; you need the SMTP log (I assume) rather than the POP3 one. – andrewsi Dec 13 '13 at 18:01
  • :O there is no logfile in the directory where i put in them but i checked the other directories only the MercuryP POP 3 Server and MercuryD POP 3 Client – user3088818 Dec 13 '13 at 18:06
  • Sir @andrewsi can you help me by team viewer cause i am really out of ideas how to solve this problem : – user3088818 Dec 13 '13 at 18:27
  • 1
    @user3088818 - sorry, I can't help with anything beyond this. For the immediate issue, you might be able to get an answer from serverfault.com - I'm sure if you search there for how to get logs from Mercury mail, you'll find something. – andrewsi Dec 13 '13 at 18:34
  • Ok sir. Thanks for helping me out even if I cant determine what i really need. :) – user3088818 Dec 13 '13 at 18:41

0 Answers0