Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can anybody help me with this problem? I posted a really similar question to thi

ID: 3712937 • Letter: C

Question

Can anybody help me with this problem? I posted a really similar question to this yesterday and nobody still answered, so if you answer this question you can answer and claim the other one also.(link at the end).

Hello, so I have a News Letter form(newsletter.php, picture attached). And what I want help with is basically that I want to use the News Letter form and email each person in my contacts database(let's suppose we have a basic contact database already, I post the pictures of mine on the end of the post) a newsletter with content and subject line. I would like also help with the database structure, so please if you would make any changes in the structure, just do it!.(could also export here the sql from phpMyAdmin in addition, would be really cool! :)

(newsletter.php):

<form action = "newsletter.php" method="post">
Subject: <input type="text" name="subject" /><br>Content:
<textarea name="content" rows = "20" cols = "50" ></textarea>
<input type="submit" name="submit" value="Send News">
</form>

(Maybe the question is too hard, and you guys don't wanna do for just a single answer)(Link to the question: https://www.chegg.com/homework-help/questions-and-answers/hello-news-letter-form-newsletterphp--want-help-basically-want-use-news-letter-form-attach-q28618460)

Subject: Content:L Send News

Explanation / Answer

//Database Creation SQL statement

create database contactfromdatabase

//Table should have primary key field, so that you can manage the table content easily for Editing and Deleting records. No much modification for table except primary key field addition.

create table users(id int primary key not null auto_increment,
firstName varchar(100),
lastName varchar(100),
Email varchar(100),
Telephone varchar(20),
Comments text)

This php code will work on Linux Server only where SMTP mail functionality is enabled. by default it will be enabled on the server.

// (newsletter.php)

<!DOCTYPE html>

<html>

<head>

<title>News Letter</title>

</head>

<body>

<form action = "newsletter.php" method="post">

Subject: <input type="text" name="subject" /><br>

Content: <textarea name="content" rows = "20" cols = "50" ></textarea>

<input type="submit" name="submit" value="Send News">

</form>

<?php

if(isset($_POST['submit']))

{

$subject = $_POST['subject'];

$content = $_POST['content'];

  

  

$server = "localhost";

$uname = "root";

$pword = "root123";

$db = "contactfromdatabase";

$dbcon = new mysqli($server, $uname, $pword, $db);

if ($dbcon->connect_error) {

die("Connection failed: " . $dbcon->connect_error);

}

$strSQL = "SELECT id, firstName, lastName, Email FROM userinfo";

$result = $dbcon->query($strSQL);

if ($result->num_rows > 0) {

while($row = $result->fetch_assoc()) {

//Get email ids from database one by one.

$email = $row['Email'];

$fname = $row['firstName'];

$lname = $row['lastName'];

//Send Mail to each email id fetched.

sendMail($email, $fname , $lname, $subject, $content);

}

} else {

echo "No records Found";

}

$dbcon->close();

}

function sendMail($email, $fname, $lname, $sub, $cont)

{

$to = "$email";

$subject = "$sub";

$message = "<b>Dear $fname $lname</b><br>News Letter<br>";

$message .= "<p>$cont</p>";

$message .="<br><br>Regards";

$message .="<br>XYZ";

$header = "From:fromemail@xyz.com ";

$header .= "CC:copytoifany@xyz.com ";

$header .= "MIME-Version: 1.0 ";

$header .= "Content-type: text/html ";

$sentStatus = mail ($to,$subject,$message,$header);

if( $sentStatus == true ) {

echo "Successfully sent";

}else {

echo "Mail sent Failed";

}

}

?>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote