desmond_ckl Posted March 16, 2011 Share Posted March 16, 2011 hi everyone ! im new to php script, hope u guys able to help me. Thank you in advance. Im using localhost xampp, i have activate my smtp and set smtp_port to 25 , smtp = localhost. when i run the script , error message show: Notice: Undefined variable: email in C:\xampp\htdocs\sendmymail.php on line 54 Notice: Undefined index: in C:\xampp\htdocs\sendmymail.php on line 54 Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\sendmymail.php on line 56 newsletter sent to: here is my php script, i have highlighted line 56 & 54 : <?php include ("ch19_include.php"); if (!$_POST) { //haven't seen the form, so display it echo "<html> <head><title>Send a Newsletter</title></head> <body> <h1>Send a Newsletter</h1> <form method=\"post\" action=\" ".$_SERVER["PHP_SELF"]."\"> <p><strong>Subject:</strong><br/> <input type=\"text\" name=\"subject\" size=\"30\"</p> <p><storng>Mail Body:</storng><br/> <textarea name=\"message\" cols=\"50\" rows=\"10\" wrap=\"virtual\"></textarea> <p><input type=\"submit\" name=\"submit\" value=\"Send It\"></p> </form> </body> </html>"; } else if ($_POST) { //want to send form, so check for required fields if (($_POST["subject"] == "")|| ($_POST["message"] == "")) { header("Location: sendmymail.php"); exit; } //connect to database doDB(); if (mysqli_connect_errno()) { // if connection fails, stop script execution printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { //otherwise, get emails from subscribers list $sql = "SELECT email FROM subscribers"; $result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli)); //create a From: mailheader $mailheaders = "From: Your Mailling List <[email protected]>"; //loop through results and send mail while ($row = mysqli_fetch_array ($result)) { set_time_limit(0); $email=$row ["$email"]; mail("email", stripslashes($_POST["subject"]), stripslashes($_POST["message"]), $mailheaders); echo "newsletter sent to: ".$email."<br/>"; } mysqli_free_result($result); mysqli_close($mysqli); } } ?> Link to comment https://forums.phpfreaks.com/topic/230779-php-and-mysql-email-help/ Share on other sites More sharing options...
sasa Posted March 16, 2011 Share Posted March 16, 2011 $email=$row ["email"]; remove $ Link to comment https://forums.phpfreaks.com/topic/230779-php-and-mysql-email-help/#findComment-1188072 Share on other sites More sharing options...
desmond_ckl Posted March 17, 2011 Author Share Posted March 17, 2011 thank you so much problem solved Link to comment https://forums.phpfreaks.com/topic/230779-php-and-mysql-email-help/#findComment-1188534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.