Jump to content


SuiGenerisMN

Member Since 11 Sep 2017
Offline Last Active Sep 19 2017 08:22 PM

Topics I've Started

Emails are being combined

14 September 2017 - 03:50 AM

Hey again, hopefully this is a bit less beginner than my previous issue but I will likely find out not.

 

I am writing a php page to send an email reminder to a list in a MySQL database. I want two separate email messages based on whether two of the columns in the database are yes/yes or the second email message if yes/no and no email message if yes/(yes or no). This is not the issue as I have the following in two separate parts of php.

 

This is appropriately selecting which 'users' to send emails to and which message.

 

Right now I am only testing the DB and don't have any real data loaded yet.

 

My issue is when I have 2+ users with the same set up combination (Yes/Yes) or (Yes/No) that the email message is 1) same message is being sent to both emails 2) the messages are being combined

 

Example

User 1 - email

Hi User 1,

Welcome to the web

From Me

Hi User 2,

Welcome to the web

From Me

 

User 2 - email

Hi User 1,

Welcome to the web

From Me

Hi User 2,

Welcome to the web

From Me

 

 

I can't figure out how to separate the messages to the different users and ensure the right information is sent to the right user.

<?php

$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
$tblname = "";

        $conn = mysqli_connect($servername, $username, $password, $dbname) or die("Unable to Connect to '$dbhost' - 
Please email support@domain.com");

    $sql = "SELECT * FROM $tblname WHERE item1='No' AND item2='Yes'";
    $result = mysqli_query ($conn, $sql)
    or die ('Error querying database. 1');
    
   while($row = mysqli_fetch_array($result)){
        $first_name = $row['First'];
        $last_name = $row['Last'];
        $stuff1 = $row['Stuff1'];
        $stuff2 = $row['Stuff2'];
        $stuff3 = $row['Stuff3'];
        $email_to = $row['Email'];
   
    $email_from = "support@domain.com"; 
    $email_subject = "Subject 1";
    $email_message .= "Hello $first_name $last_name,\n";
    $email_message .= "\n";
    $email_message .= "Message\n";
    $email_message .= "\n";
    $email_message .= "Message\n";
    $email_message .= "\n";
    $email_message .= "Message\n";
    $email_message .= "\n";
    $email_message .= "Message\n";
    $email_message .= "Message\n";
    
// create email headers
mail($email_to, $email_subject, $email_message, 'From:' . $email_from);
echo 'Email sent to: ' . $email_to. '<br>';

 
}
mysqli_close($conn);

?>

<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
$tblname = "";

        $conn = mysqli_connect($servername, $username, $password, $dbname) or die("Unable to Connect to '$dbhost' - Please email support@domain.com");

    $sql = "SELECT * FROM $tblname WHERE item1='Yes' AND item2='Yes'";
    $result = mysqli_query ($conn, $sql)
    or die ('Error querying database. 2');
   
    while($row = mysqli_fetch_array($result)){
        $first_name2 = $row['First'];
        $last_name2 = $row['Last'];
        $stuff12 = $row['Stuff1'];
        $stuff22 = $row['Stuff2'];
        $stuff32 = $row['Stuff3'];
        $email_to2 = $row['Email'];
     
    $email_from = "support@domain.com"; 
    $email_subject2 = "Subject 2";
    $email_message2 .= "Hello $first_name2 $last_name2,\n";
    $email_message2 .= "\n";
    $email_message2 .= "Message2\n";
    $email_message2 .= "\n";
    $email_message2 .= "Message2\n";
    $email_message2 .= "\n";
    $email_message2 .= "Message2\n";
    $email_message2 .= "\n";
    $email_message2 .= "Message2\n";
    $email_message2 .= "Message2\n";
    
// create email headers
mail($email_to2, $email_subject2, $email_message2, 'From:' . $email_from);
echo 'Email sent to: ' . $email_to2. '<br>';       
            
}
mysqli_close($conn);
?>

Another, sigh, "unexpected end of file" error

11 September 2017 - 09:21 PM

I am sure to get some flack for this, but I have searched google, and this forum, and found some great advice, but I am still getting the "unexpected end of file" error.

 

Any assistance is appreciated.

 

Background, I have an HTML form that submits an email to me and I would also like to send the form data to a DB.

 

The emailform.php has the include ("loaddb.php"); at the top. The emailform.php works fine, but the data never gets entered into the DB.

<?php

$servername = “localhost”;
$username = “”;
$password = “”;
$dbname = “”;
$tblname = “”;

If (isset($_POST[‘submit’]))
	{
		$conn = mysqli_connect($servername, $username, $password);

		if (!$conn)
	{
		die('Could not connect: ' . mysqli_error());
	}
		mysqli_select_db($dbname, $conn);

		$first_name = $_POST['first_name'];
		$last_name = $_POST['last_name'];
		$email_from = $_POST['email'];
		$telephone = $_POST['telephone'];
		

		$first_name = mysqli_real_escape_string($first_name);
		$last_name = mysqli_real_escape_string($last_name);
		$email = mysqli_real_escape_string($email);
		$telephone = mysqli_real_escape_string($telephone);
		
	$query = "
	INSERT INTO $dbname.$tblname(‘ID’, ‘First’, ‘Last’, ‘Email’, ‘Phone’)
	VALUES (NULL, '$first_name', '$last_name', '$email', '$telephone');”;
        }

	mysqli_close($conn);

?>

I checked whitespace, all brackets appear to be closing. Error shows as last line with the closing "?>" and I am stumped.

 

Again, sorry for "another one of these error" questions but I just cannot get this to work and have been trying everything I can think of.