-1

this is the body of an email sent to admin. it should say "a new store called ABC has submitted their location for approval. Please login to XYZ to approve the request"

I Figured out how to pull the store name and put it in email body, but i cant get the a href link to attach to the "XYZ" part

mail(ADMINISTRATOR_EMAIL, sprintf("Super Store Finder - New store has been 
added"),  sprintf("A new store " .  $_POST['name'] . " has submitted their 
location for approval.  Please login to "<a href= 
'https://blablbabla.com/admin'>XYZ</a>" to approve the 
request), "From: no-reply@gmail.com");

the error i got is

Parse error: syntax error, unexpected 'href' (T_STRING) in /home/devhand/public_html/includes/validate.php on line 191
  • The syntax highlighting in the question posted here should give you everything you need. You seem to have arbitrarily added double-quotes that you don't need or even want, and they are terminating the string. Remove them. – David Jan 08 '19 at 19:43
  • 1
    Also note, there's no point using sprintf if you're just going to concatenate the variables in. Use placeholders: `sprintf("A new store %s has submitted...", $_POST['name'])` – Alex Howansky Jan 08 '19 at 19:44

1 Answers1

1

This is a simple syntax issue involving concatenation:

In order to send emails as HTML, you'll need the right headers:

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

mail(ADMINISTRATOR_EMAIL, sprintf("Super Store Finder - New store has been 
added"),  sprintf("A new store " .  $_POST['name'] . " has submitted their 
location for approval.  Please login to <a href= 
'https://blablbabla.com/admin'>XYZ</a> to approve the 
request"), "From: no-reply@gmail.com", $headers);

Notice how I removed the " marks from around the <a href> tag? Also, added in a missing " to the end of your sprintf() function.

Edit: Added some headers to the code to ensure it's sent as HTML.

Adam
  • 1,149
  • 2
  • 14
  • 21