开发者

Email with PHP after conditional statement

开发者 https://www.devze.com 2023-02-16 02:55 出处:网络
So, I\'m trying to do a very simple thing - send an email using PHP.I\'ve looked through other queries on stack and none of them involve a conditional statement, so I wanted to check and see if I coul

So, I'm trying to do a very simple thing - send an email using PHP. I've looked through other queries on stack and none of them involve a conditional statement, so I wanted to check and see if I could get some quick advice. See the conditional below that then send a confirmation / thank you email to someone who donated to my organization.

Could it be that I first have the code echoing / printing a statement and then running the mail() function?

if ((isset($_POST['submitted'])) && ($ack!="SUCCE开发者_如何学PythonSS"))  {

    $_SESSION['reshash']=$resArray;
    $location = "https://globalcitizenyear.org/wp-content/themes/deMar/APIError.php";
         header("Location: $location");
   } elseif ($ack =="SUCCESS") {

       echo ("<h2>Thank You</h2><p>Thank you for your generous donation of $$amount. You will receive an email confirmation with an attached tax receipt.</p>");
        $body = "Dear $firstName, 
        /n/nThank you ...

/n/nAs I travel the country, ...

/n/nPlease accept my deepest gratitude for your contribution.
/n/nSincerely,
/n/nAbigail Falik
/n/nFounder and CEO
/nGlobal Citizen Year";

**$body = wordwrap($body,70);
mail("$email",'Thank you for your donation to Global Citizen Year (Important tax receipt)', $body,"From:donations@globalcitizenyear.org");**

   } 
    else {
     // Display Form ?>


Your code looks ok. It's best to send the mail first and check whether the function was successful. Then you can echo out "You will receive an email confirmation..." if successful, and some other message if the mail() call failed. With the mail() function, though, problems are usually later in the mail process. Getting a 'true' return from that function doesn't mean that Everything has worked in the email world.

With other functions, like DB writes, you will get a solid success or failure returned from the function and should act on it appropriately. That means you want to run the function before printing out a message saying everything went fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消