Hi guys ive got a problem with my mail() function.

if(mail('$email', 'test', 'test message'))
{
  echo('ok');
}
else
{
echo('not ok');
}

im trying to test this out.
ive tried manually inputting the email e.g. 12345@hotmail.com
the email is sent and i can receive it.
However, when i replace it with $email, the email is not sent.
when i echo $email it does show 12345@hotmail.com

what am i doing wrong?

Thanks
Danny

You cannot use a variable in a single quoted string. Use:

mail($email, 'test', 'test message')

or

mail("$email", 'test', 'test message')

hey thx man that solved my problem!

btw is there a code to add attachments? e.g image files?

Technically yes. You could MIME encode the attachments (see php.net for details). However, if you use a mail package (PEAR, PHPMailer, etc.) it will be much easier.

Thanks so much for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.