Jump to content

Recommended Posts

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

<abc@gmail.com>";

 

//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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.