sending email from .php

php newbie here -

  • I am trying to send an email from the following .php file on my site:
<? $to = “[email protected]”; $subject = “Hello world!”; $from = “From: [email protected]”; $message = “Hi there, how are you?”; // send the mail: mail($to, $subject, $message, $from); // give notification in the browser: echo “I mailed “ . $to . “
”; echo $from . “
”; echo $subject. “

”; echo $message; ?>

I get an error message “unexpected @ on line 2” which I can’t explain.

am I missing something obvious? Thanks!

You are using wrong quotes. You have to use normal single or double quotes.

[size=36pt]“[/size] vs [size=36pt]’[/size] or [size=36pt]"[/size]

And you should not use short tags, change <? to <?php :slight_smile:

The "Wrong Quotes’ are known in programming as back ticks.

In PHP per the documentation: PHP will attempt to execute the contents of the backticks as a shell command. Use of the backtick operator is identical to shell_exec().

In MySQL backticks are used to escape column and table names using Mysql’s reserved words. Using reserved words for naming is just a bad idea to do in the first place.

In punctuation they are known as a grave accent

Uh, are you confusing “ with ` ?

so if you sub in the ’ for " in the top section it mails fine.
when you want to print the I mailed to, etc. I think you will need to ‘get’ the info again to echo it.
there may be a way without re-querying the $to, $from etc but I don’t know it right off the top
the email portion works, though if " is replaced with ’


Sponsor our Newsletter | Privacy Policy | Terms of Service