Jump to content

Recommended Posts

I need some help over here.

 

I want to send an email to my friends by checking the database and extract the id.

After extracting the id from the database, i want to include a URL with the id.

E.g.

www.abc.php?35 (35 is the id)

www.abc.php?40 (40 is the id)

 

May I know how to send an email with multiple url?

Is it using a for loop in the php email function?

 

Your help is greatly appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/255260-sending-email/
Share on other sites

To send one ID to the corresponding email;

use a while loop to cycle through the ids from the database and then use the mail() function to send an email to each.

 

Or if you want to send all the ids to one email;

use a while loop to cycle through the ids and add it to a string which will be emailed using mail();

Link to comment
https://forums.phpfreaks.com/topic/255260-sending-email/#findComment-1308779
Share on other sites

..

So basically, you want to loop through the content extracted from the database and display a link for each entry. Then you want the user to click each link which would send an e-mail to whoever's entry was clicked. Is that correct?

No..i'm trying to extract my friend appointment_id and send an email to them if they have any appointment date on the following week.

And the email content will be the link to their appointment date to let them confirm their appointment date.

 

E.g. of the email content

www.abc.php?40 (40 will be my friend appointment_id)

www.abc.php?42 (42 will be my friend appointment_id)

 

Hope you get what i mean

Link to comment
https://forums.phpfreaks.com/topic/255260-sending-email/#findComment-1308899
Share on other sites

Email are stored in session after customer log in..

They will click on the button to send..

 

This is the code after clicking on the button

<?php

include 'config.php'; //my configuration, username, password etc

$sql = "SELECT * from customer c WHERE c.uid = " . $_SESSION['uid'] . "and c.appointmentDate BETWEEN CURRENT_DATE AND (CURRENT_DATE + INTERVAL 7 DAY )";
$sql1= exeSelectQuery($sql);


if (isset($_POST['submit'])) { //after clicking on the button 
    if ($sql1) {
        $to = $_SESSION['mail'];
        $subject = "Appointment Reminder";
        $body = "Dear Customer \n\n" .
                "Please confirm your following appointment date by clicking on the link  . \n" .
                "http://abc.php?40  \n" . #40 is the appointment_id
                "http://abc.php?42  \n" . #42 is the appointment_id
                "Regard\n" .
                "Admin";
        $header = 'From: myemail@abc.com' ;
        $deliver = mail($to, $subject, $body, $header);

        if ($deliver) {
            echo "Appointment Reminder Sent. \n";
        } else {
            echo "Appointment Reminder Sending Fail. \n";
        }
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/255260-sending-email/#findComment-1309073
Share on other sites

<?php

include 'config.php'; //my configuration, username, password etc

$sql = "SELECT * from customer c WHERE c.uid = " . $_SESSION['uid'] . "and c.appointmentDate BETWEEN CURRENT_DATE AND (CURRENT_DATE + INTERVAL 7 DAY )";
$sql1= exeSelectQuery($sql);


if (isset($_POST['submit'])) { //after clicking on the button 
    if ($sql1) {
        $to = $_SESSION['mail'];
        $subject = "Appointment Reminder";
        $body = "Dear Customer \n\n" .
                "Please confirm your following appointment date by clicking on the link  . \n";

while ($row = mysql_fetch_assoc($sql)) {
$body .= "http://abc.php?{$row['appointment_id']} \n";
}

$body .=  "Regard\n" .
                "Admin";
        $header = 'From: myemail@abc.com' ;
        $deliver = mail($to, $subject, $body, $header);

        if ($deliver) {
            echo "Appointment Reminder Sent. \n";
        } else {
            echo "Appointment Reminder Sending Fail. \n";
        }
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/255260-sending-email/#findComment-1309088
Share on other sites

You need to put in a html anchor tag to link it...

while ($row = mysql_fetch_assoc($sql)) {
$body .= "<a href='http://abc.php?{$row['appointment_id']}'>http://abc.php?{$row['appointment_id']}</a> \n";
}

 

#edit

you should set the content type to HTML if you're having links in there

 

read this

//FROM php.net
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Link to comment
https://forums.phpfreaks.com/topic/255260-sending-email/#findComment-1309099
Share on other sites

This is my code

<?php

include 'config.php';

$sql = "SELECT * from customer c WHERE c.uid = " . $_SESSION['uid'] . "and c.appointmentDate BETWEEN CURRENT_DATE AND (CURRENT_DATE + INTERVAL 7 DAY )";
$sql1 = exeSelectQuery($sql);

if (isset($_POST['submit'])) {
    if ($sql1) {
        $to = $_SESSION['mail'];
        $subject = "Appointment Reminder";
        $body = "Dear Customer <br/><br/>" .
                "Please confirm your following appointment date by clicking on the link. <br/>";

        while ($row = mysqli_fetch_assoc($sql)) {
            $body .= "<a href='http://abc.php?{$row['appointment_id']}'>
            http://abc.php?{$row['appointment_id']}</a> <br/>";
        }
        $body .= "Regard<br/>" .
                "Admin";
        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: myemail@abc.com' . "\r\n";
        $deliver = mail($to, $subject, $body, $headers);

        if ($deliver) {
            echo "Appointment Reminder Sent. \n";
        } else {
            echo "Appointment Reminder Sending Fail. \n";
        }
    }
}
?>

 

This is the output which I have received.

 

Dear Customer

 

Please confirm your following appointment date by clicking on the link.

 

 

Yours Sincerely

Admin

Link to comment
https://forums.phpfreaks.com/topic/255260-sending-email/#findComment-1309200
Share on other sites

change this

while ($row = mysqli_fetch_assoc($sql)) {

to

while ($row = mysqli_fetch_assoc($sql1)) {

you are using the wrong variable in your fetch, I suggest using more relative variable names to avoid this issue in the future.  Also, checking mysql_num_rows($sql1) will allow you to check for no appointments and handle that accordingly.

Link to comment
https://forums.phpfreaks.com/topic/255260-sending-email/#findComment-1309205
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.