Jump to content

2 Emails


Go to solution Solved by kicken,

Recommended Posts

For the likes of me, I cannot figure out how to send two emails at the same time.  I have seen examples, but none of them work.  I need to send a message to me, that someone has reserved a certain day for scuba diving... this one works.  It gives me that email, but I cannot get the second one to work unless I put a certain email in, like mine.  I don't want that.  I need the user that made the reservations email address so I can send them the confirmation number and information.  This is what I have so far.  Thanks for any help.

 

if (isset($_POST["submit"])) {
    unset($_POST[submit]);
    $servername = "127.0.0.1";
    $username = "";
    $password = "";
    $dbname = "";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
    }

     $sql = "SELECT * FROM reservations WHERE oid = $_GET[oid]";
     $result = $conn->query($sql);

     $fname = $_GET['fname'];
     $lname = $_GET['lname'];
     $phone = $_GET['phone'];
     $dropdown = $_GET['dropdown'];
     $oid = $_GET['oid'];
     $dived = $_GET['dove'];
     $email = $_GET['email'];
     $date = $_GET['$date'];


    if(! get_magic_quotes_gpc() ) {
      $fname = addslashes ($fname);
      $lname = addslashes ($lname);
      $email = addslashes ($email);
      $phone = addslashes ($phone);
      $dived = addslashes ($dived);
      $dropdown = addslashes ($dropdown);
      $date = addslashes ($date);
      $resnum = addslashes ($code);

      } else {
      $fname = $_GET['name'];
      $email = $_GET['email'];
      $lname = $_GET['lname'];
      $phone = $_GET['phone'];
      $dived = $_GET['dived'];
      $dropdown = $_GET['dropdown'];
      $date = $_GET['$date'];
    }
      $sql = "INSERT INTO reservations ".
          "(fname,lname,email,phone,dived,dropdown,reserved,resnum) "."VALUES ".
          "('$fname','$lname','$email','$phone','$dived','$dropdown','$time','$resnum')";
          
          
        
$to_email = 'myemail@hotmail.com'; //This one works
$subject = 'Navarre Scuba Reservation';
$message = "A Reservation has been make on: $time\n \n".
"Username: $fname $lname"."\n\nContact Phone: $phone.\r\nEmail Address: $email\r\n\nReservation number: $code\r\n\nNavarre Beach Scuba Reservation Autoresponder";

$headers = 'From: noreply@navarrebeachscuba.com';
mail($to_email,$subject,$message,$headers);



//This one I've tried so many different ways it's crazy.  This one needs the users email that makes the reservation so I can send their info.
$to = "'.$email.'";
$from = 'navarrebeachscuba.com'; 
$fromName = 'Navarre Beach Scuba'; 
 
$subject = "Send HTML Email in PHP by Navarre Beach Scuba"; 
 
$htmlContent = ' 
    <html> 
    <head> 
        <title>Welcome to Navarre Beach Scuba</title> 
    </head> 
    <body> 
        <h1>Thanks you for your reservation. We cant wait to get started. See you soon!</h1> 
        <table cellspacing="0" style="border: 2px dashed #FB4314; width: 100%;"> 
            <tr> 
                <th>Name:</th><td>Navarre Beach Scuba</td> 
            </tr> 
            <tr style="background-color: #e0e0e0;"> 
                <th>Email:</th><td>admin@navarrebeachscuba.com</td> 
            </tr> 
            <tr> 
                <th>Website:</th><td><a href="http://www.navarrebeachscuba.com">Website</a></td> 
            </tr> 
        </table> 
    </body> 
    </html>'; 
 
// Set content-type header for sending HTML email 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
 
// Additional headers 
$headers .= 'From: '.$fromName.'<'.$from.'>' . "\r\n"; 
// $headers .= 'Cc: welcome@example.com' . "\r\n"; 
// $headers .= 'Bcc: welcome2@example.com' . "\r\n"; 
 
// Send email 
if(mail($to, $subject, $htmlContent, $headers)){ 
    echo 'Email has sent successfully.'; 
}else{ 
   echo 'Email sending failed.'; 
}

Also,  I have unset the submit so that it wouldn't post a double email, which changes the confirmation number... but it's not working either.  I'm almost bald as it is :D don't need to lose anymore  hair.  Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/316167-2-emails/
Share on other sites

  • Solution
7 minutes ago, XCalibre3 said:
//This one I've tried so many different ways it's crazy.  This one needs the users email that makes the reservation so I can send their info.
$to = "'.$email.'";
$from = 'navarrebeachscuba.com'; 

Neither of those is a valid email address.  Your attempt at $to has extra '..' surrounding the email.  Your attempt at $from has no local part (before the @).

I would highly suggest using a library to handle your emails instead of trying to use mail() directly.  Symfony/mailer is my choice.

 

Link to comment
https://forums.phpfreaks.com/topic/316167-2-emails/#findComment-1607544
Share on other sites

11 minutes ago, kicken said:

Neither of those is a valid email address.  Your attempt at $to has extra '..' surrounding the email.  Your attempt at $from has no local part (before the @).

I would highly suggest using a library to handle your emails instead of trying to use mail() directly.  Symfony/mailer is my choice.

 

Yes I know I have the ".." there, I was testing a billion ways to make it work.  It should get the users email from the GET email, but it's not doing it.  As stated,  the first one works using the GET info, but the second one is not.  I don't get it.  I will also look at your link.  Thank you.

And I also tried:

$to = "$email";

I've tried 100 ways lol

Edited by XCalibre3
Link to comment
https://forums.phpfreaks.com/topic/316167-2-emails/#findComment-1607545
Share on other sites

Okay, I updated the information you suggested.... no go :(  *cries* lol

 

//This one I've tried so many different ways it's crazy.  This one needs the users email that makes the reservation so I can send their info.
$to = "$email";
$from = "noreply@navarrebeachscuba.com"; 
$fromName = "Navarre Beach Scuba"; 
 
$subject = 'Send HTML Email in PHP by Navarre Beach Scuba'; 
 
$htmlContent = ' 
    <html> 
    <head> 
        <title>Welcome to Navarre Beach Scuba</title> 
    </head> 
    <body> 
        <h1>Thanks you for your reservation. We cant wait to get started. See you soon!</h1> 
        <table cellspacing="0" style="border: 2px dashed #FB4314; width: 100%;"> 
            <tr> 
                <th>Name:</th><td>Navarre Beach Scuba</td> 
            </tr> 
            <tr style="background-color: #e0e0e0;"> 
                <th>Email:</th><td>admin@navarrebeachscuba.com</td> 
            </tr> 
            <tr> 
                <th>Website:</th><td><a href="http://www.navarrebeachscuba.com">Website</a></td> 
            </tr> 
        </table> 
    </body> 
    </html>'; 
 
// Set content-type header for sending HTML email 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
 
// Additional headers 
$headers = 'From: ' . $fromName . "\r\n";
// $headers .= 'Cc: welcome@example.com' . "\r\n"; 
// $headers .= 'Bcc: welcome2@example.com' . "\r\n"; 
 
// Send email 
if(mail($to, $subject, $htmlContent, $headers)){ 
    echo 'Email has sent successfully.'; 
}else{ 
   echo 'Email sending failed.'; 
}

 

Link to comment
https://forums.phpfreaks.com/topic/316167-2-emails/#findComment-1607547
Share on other sites

Several things - some are minor, some not so much.

First and foremost, you're concatenating strings in places you don't need to - it'll get confusing and bite you in the end. Secondly, magic quotes have been deprecated (I thought they were removed, tbh) for quite a long time, and add_slashes() is pointless. Use prepared statements in PDO and actually be secure. Finally, as to your reported problem - php's mail() function is ... not great. Use PHPMailer or (as kicken suggested) Symfony/mailer. Either will make your life much, much easier, and you can debug the transaction much more easily.

Link to comment
https://forums.phpfreaks.com/topic/316167-2-emails/#findComment-1607548
Share on other sites

36 minutes ago, maxxd said:

Several things - some are minor, some not so much.

First and foremost, you're concatenating strings in places you don't need to - it'll get confusing and bite you in the end. Secondly, magic quotes have been deprecated (I thought they were removed, tbh) for quite a long time, and add_slashes() is pointless. Use prepared statements in PDO and actually be secure. Finally, as to your reported problem - php's mail() function is ... not great. Use PHPMailer or (as kicken suggested) Symfony/mailer. Either will make your life much, much easier, and you can debug the transaction much more easily.

 

I actually got this to work, but doesn't show html... but will look into phpmailer.  Does it have to be in the main directory?

 

$to = "$email";
$subject = 'Send HTML Email in PHP by Navarre Beach Scuba'; 
 
$htmlContent = ' 
    <html> 
    <head> 
        <title>Welcome to Navarre Beach Scuba</title> 
    </head> 
    <body> 
        <h1>Thanks you for your reservation. We cant wait to get started. See you soon!</h1> 
        <table cellspacing="0" style="border: 2px dashed #FB4314; width: 100%;"> 
            <tr> 
                <th>Name:</th><td>Navarre Beach Scuba</td> 
            </tr> 
            <tr style="background-color: #e0e0e0;"> 
                <th>Email:</th><td>admin@navarrebeachscuba.com</td> 
            </tr> 
            <tr> 
                <th>Website:</th><td><a href="http://www.navarrebeachscuba.com">Website</a></td> 
            </tr> 
        </table> 
    </body> 
    </html>'; 
 
// Set content-type header for sending HTML email 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
 
// Additional headers 
$headers = "From: noreply@navarrebeachscuba.com" . "\r\n"; 
// $headers .= 'Cc: welcome@example.com' . "\r\n"; 
// $headers .= 'Bcc: welcome2@example.com' . "\r\n"; 
 
// Send email 
if(mail($to, $subject, $htmlContent, $headers)){ 
    echo 'Email has sent successfully.'; 
}else{ 
   echo 'Email sending failed.'; 
}

 

Link to comment
https://forums.phpfreaks.com/topic/316167-2-emails/#findComment-1607549
Share on other sites

7 minutes ago, ginerjm said:

And - why can't the first be also sent to you with all the info that it has?

Just a thought.

Yes, the first mail I use sends the information to me saying so and so reserved so and so date and gives me name, phone, email, etc...

Second mail is sent to them, which provides their information with their reservation number.

I have it working, but might have to remove the html, as it's not showing... it just shows this in the email.

 

html>
    <head>
        <title>Welcome to Navarre Beach Scuba</title>
    </head>
    <body>
        <h1>Thanks you for your reservation. We cant wait to get started. See you soon!</h1>
        <table cellspacing="0" style="border: 2px dashed #FB4314; width: 100%;">
            <tr>
                <th>Name:</th><td>Navarre Beach Scuba</td>
            </tr>
            <tr style="background-color: #e0e0e0;">
                <th>Email:</th><td>admin@navarrebeachscuba.com</td>
            </tr>
            <tr>
                <th>Website:</th><td><a href="[http://www.navarrebeachscuba.com">Website</a></td]http://www.navarrebeachscuba.com">Website</a></td>
            </tr>
        </table>
    </body>
    </html>

 

Link to comment
https://forums.phpfreaks.com/topic/316167-2-emails/#findComment-1607553
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.