textbox Posted May 13, 2007 Share Posted May 13, 2007 Hello; // Let's mail the user! $subject = "Activate your TextBox!"; $message = "Dear $forename $surname, Thank you for registering at TextBox! You are two steps away from logging in and accessing our exclusive members area. To activate your membership, please click here: url Once you activate your memebership, you will be able to login with the following information: Username: $username Password: $random_password Thanks! Textbox This is an automated response, please do not reply!"; mail($email, $subject, $message, "From: TextBox!<textbox@fruitsticksmedia.com>\n X-Mailer: PHP/" . phpversion()); echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!'; } I know i need to enter the $to parameter, but do i need to have a line somewhere that sends the actual e-mail?? Something like mail ($to, $subject etc.... Any help would be great. Im a little stuck as to why it wont send! Quote Link to comment https://forums.phpfreaks.com/topic/51129-solved-e-mail/ Share on other sites More sharing options...
trq Posted May 13, 2007 Share Posted May 13, 2007 do i need to have a line somewhere that sends the actual e-mail?? You do have that line, here.... mail($email, $subject, $message, "From: TextBox!<textbox@fruitsticksmedia.com>\n X-Mailer: PHP/" . phpversion()); Where have you defined $email? Quote Link to comment https://forums.phpfreaks.com/topic/51129-solved-e-mail/#findComment-251683 Share on other sites More sharing options...
Wuhtzu Posted May 13, 2007 Share Posted May 13, 2007 Your mail() syntax is correct, mail(to, subject, message, headers), but I think your header is wrong. The header syntax is like: "header1" . "\r\n" . "header2" . "\r\n" . "header3" . "\r\n" For example: "MIME-Version: 1.0" . "\r\n" . "Content-Type: text/plain; charset=UTF-8" . "\r\n" . "From: Name <your@email.com>" . "\r\n" . "Reply-To: Name <your@email.com>" . "\r\n" I don't know why you have the "X-Mailer: PHP/" in a new line in the From header... Try alter your header according to what I have described above Quote Link to comment https://forums.phpfreaks.com/topic/51129-solved-e-mail/#findComment-251689 Share on other sites More sharing options...
Wuhtzu Posted May 13, 2007 Share Posted May 13, 2007 By the way, when you are using functions which returns 1 or true on success and 0 or false on failure you should take advantage of that and do something like: $sendmail = mail(to, subject ... ); if($sendmail) { echo "Success"; } else { echo "Failure"; } Of course you can tell failure by the lack of mail in your mailbox, but a lot of things can go wrong when sending e-mails apart form the mail() function not succeeding. the mail server being slow ect. So to check the mail() output (true / false) can save some time... Quote Link to comment https://forums.phpfreaks.com/topic/51129-solved-e-mail/#findComment-251692 Share on other sites More sharing options...
textbox Posted May 13, 2007 Author Share Posted May 13, 2007 You do have that line, here.... mail($email, $subject, $message, "From: TextBox!<textbox@fruitsticksmedia.com>\n X-Mailer: PHP/" . phpversion()); Where have you defined $email? Thanks for that. $email is defined as a user input from a form. My full script is below. <? include 'inc/global.php'; //make the local variable for the text activation // Define post fields into simple variables $forname = $_POST['forename']; $surname = $_POST['surname']; $email = $_POST['email']; $username = $_POST['username']; $source = $_POST['source']; //strip some slashes in case the user entered any escaped characters $forename = stripslashes($forename); $surname = stripslashes($surname); $email = stripslashes($email); $username = stripslashes($username); $source = stripslashes($source); // Do some error checking on the form posted fields if((!$forename) || (!$surname) || (!$email) || (!$username)){ echo 'You did not submit the following required information! <br />'; if(!$forename){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$surname){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } include 'sign.php'; /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! } /* Let's do some checking and ensure that the user's email address or username does not exist in the database */ //$sql_email_check = mysql_query("SELECT email FROM users // WHERE email='$email'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used by another member in our database. Please submit a different Email address!<br />"; unset($email); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'signup.php'; // Show the form again! exit(); // exit the script so that we do not create this account! } /*create the account now!*/ /* Random Password generator. http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php We'll generate a random password for the user and encrypt it, email it and then enter it into the db. */ function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_password = makeRandomPassword(); $db_password = md5($random_password); // Enter info into the Database. $mobact = makeMobilecode(); //change the mobile number to accomodate the sms function $info2 = htmlspecialchars($info); $sql = mysql_query("INSERT INTO users (username, email, forename, surname, password, gender, source, location, network, signup_date,mobact) VALUES('$username', '$email', '$forename', '$surname', '$db_password', '$gender', '$source', '$location', '$network', now(),'$mobact')") or die (mysql_error()); include ("signup.php"); if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $to = $email; $subject = "Activate your TextBox!"; $message = "Dear $forename $surname, Thank you for registering at TextBox! You are two steps away from logging in and accessing our exclusive members area. To activate your membership, please click here: http://www.textbox.fruitsticksmedia.com/staged/activate.php?id=$userid&code=$db_password Once you activate your memebership, you will be able to login with the following information: Username: $username Password: $random_password Thanks! Textbox This is an automated response, please do not reply!"; mail($to, $subject, $message, "From: TextBox!<textbox@fruitsticksmedia.com>\n X-Mailer: PHP/" . phpversion()); echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!'; } //send a text message to the user to tell them they have signed up properly //this is at no cost to the user //set up a string for the mobile validation $usr = "***"; // Supply your username here $pwd = "***"; // Supply your password here $replyroutetouse = *; // Send out on premiere route $replysenderid = "***"; // Set Sender ID $sendtimenow = date('YmdHis'); $replytext = "Hello there thanks for signing up $username.This is your activation code: $mobact "; $itapi = "***"; $params = "usr=$usr&pwd=$pwd&from=$replysenderid&to=$source&send=$sendtimenow&type=text&route=$replyroutetouse&txt=".urlencode($replytext); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $itapi); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $returned = curl_exec($ch); curl_close($ch); // Now respond to the server. print( "OK" ); // this will simply print to the output stream, and generate a 200 Server Response, indicating a successful communication. ?> Quote Link to comment https://forums.phpfreaks.com/topic/51129-solved-e-mail/#findComment-251698 Share on other sites More sharing options...
Wuhtzu Posted May 13, 2007 Share Posted May 13, 2007 Did you try to modify the header? I'm almost certain thats where things go wrong and of course if the $email is wrong Quote Link to comment https://forums.phpfreaks.com/topic/51129-solved-e-mail/#findComment-251711 Share on other sites More sharing options...
textbox Posted May 13, 2007 Author Share Posted May 13, 2007 Hello Wuhtzu , just modified the header and it works fine! Of course, i will be building an e-mail check into the file Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/51129-solved-e-mail/#findComment-251717 Share on other sites More sharing options...
textbox Posted May 13, 2007 Author Share Posted May 13, 2007 Just as an addon to this, how would i include an image in my e-mail?! // Let's mail the user! $to = $email; $subject = "Activate your TextBox!"; $message = " Dear $forename $surname, Thank you for registering at TextBox! You are two steps away from logging in and accessing our exclusive members area. To activate your membership, please click here: http://www.minisite.co.uk/site/activate.php?id=$userid&code=$db_password Once you activate your memebership, you will be able to login with the following information: Username: $username Password: $random_password Thanks! Textbox This is an automated response, please do not reply!"; mail($to, $subject, $message, "MIME-Version: 1.0" . "\r\n" . "Content-Type: text/plain; charset=UTF-8" . "\r\n" . "From: Name <nick@fruitsticksmedia.com>" . "\r\n" . "Reply-To: Name <your@email.com>" . "\r\n"); Thanks again, Nick Quote Link to comment https://forums.phpfreaks.com/topic/51129-solved-e-mail/#findComment-251732 Share on other sites More sharing options...
Wuhtzu Posted May 13, 2007 Share Posted May 13, 2007 If you want to include an image you could do something like this: $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-Type: text/html; charset=UTF-8" . "\r\n"; $headers .= "From: Name <your@email.com>" . "\r\n"; $message = "<html><body><p>Hello here is an image</p><img src="http://yourdomain.com/image.jpg"></body></html>" So just change the "Content-Type" header to "text/html" and then use normal html to display pictures, tabels, links ect. Quote Link to comment https://forums.phpfreaks.com/topic/51129-solved-e-mail/#findComment-251952 Share on other sites More sharing options...
textbox Posted May 13, 2007 Author Share Posted May 13, 2007 Thanks Wuhtzu:) Quote Link to comment https://forums.phpfreaks.com/topic/51129-solved-e-mail/#findComment-251980 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.