-
Dec 6th, 2020, 01:58 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Can't get Image to show up in Email?
I have a PHP script in which it loops through a database extracting an email address from each record. This ultimately sends a formatted email to all the emails. The problem I'm having is that the message contains an image, however, the image is not showing up in the email. I have included the PHP script. The image on the server resides in a directory called "img".
Code:
<?php
// Database information is here
$Email = $message = $success = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "Select email From wp_ig_contacts;";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
$myEmailAddress = "test@test.com";
$subject = "Weekly Devotional";
while($row = $result->fetch_assoc()) {
$Email = $row["email"];
$nameErr = $name = "";
$whitelist = array('txtDevo');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["txtDevo"])) {
$nameErr = "Name is required";
}
else {
$name = $_POST["txtDevo"];
}
$message = "<h3>WEEKLY DEVOTIONAL</h3>";
$message = $message . '<img src="GodsGlory2_r.jpg" style="margin-left: 30px">'; Here is the line in question
$message = $message . '<br><br>';
$message = $message . '<p style="width: 55%; text-align: justified; margin-left: 40px">' . $name . '</p>';
$headers = "From: Dr. Branson" . "<" . $myEmailAddress . ">" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html\r\n";
if (mail($Email, $subject, $message, $headers)) {
$success = true;
}
else {
echo("Message failure!");
}
}
}
if ($success = true) {
echo("<script>alert('Message sent successfully!');</script>");
}
} else {
echo "0 results";
}
$conn->close();
?>
Last edited by blakemckenna; Dec 6th, 2020 at 02:01 AM.
Blake
-
Dec 6th, 2020, 08:24 PM
#2
Re: Can't get Image to show up in Email?
You're using a relative image.. not sure what that would look for in an email.
You'll want to either use the full URL IE)
Code:
<img src="https://www.yoursite.com/GodsGlory2_r.jpg" />
or base64 encode the byte array of the image, like so:
Code:
<img src="data:image/png;base64,<yourbase64stringhere>" />
I think there are other ways, like attaching the image to the email and then using that as the source, but I've never done it that way.
-
Dec 7th, 2020, 02:36 AM
#3
Thread Starter
PowerPoster
Re: Can't get Image to show up in Email?
Thanks kfc...I used the full URL and that worked.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|