Link to home
Start Free TrialLog in
Avatar of Jason
JasonFlag for Australia

asked on

Emailing page

<?php mail(MAIL_ADDRESS, MAIL_SUBJECT, $content, $headers);?>

When this code is put on the page it automatically send the page.

<a href="" onclick= <?php mail(MAIL_ADDRESS, MAIL_SUBJECT, $content, $headers);?> >Email</a>

I was trying to put in a <a> so when the user clicks onto email it is sent.  

not automatically

Any advise
Avatar of Kiran Paul VJ
Kiran Paul VJ
Flag of India image

try this

page1.php

<script language="javascript">
function SendMail()
{
  window.location.href='page2.php';
}
</script>
<a href="" onclick="Send Mail();" >Email</a>

page2.php
<?php
mail(MAIL_ADDRESS, MAIL_SUBJECT, $content, $headers);
header("Location:page1.php");?>
Avatar of vnsmanian2006
vnsmanian2006


U may try this

send_mail.php
-------------------
<script language="javascript">
function SendMail() {
  <?php mail(MAIL_ADDRESS, MAIL_SUBJECT, $content, $headers); ?>
}
</script>

<a href="" onclick="Send Mail();" >Email</a>
Avatar of Jason

ASKER

vnsmanian2006:
the script doesn't work

it auto send mail when page loads and email body is blank

kiranvj:

I would prefer a script that does not require another page

Any other ideas
Avatar of Jason

ASKER

kiranvj:

I tried your script it would work fine but the body content of the email does not pass over.

The email sends the subject sends but the $content, $headers does not send.

I got this variables with this code
<?php ob_start();?>

<?php $content=ob_get_flush();
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
?>       
ASKER CERTIFIED SOLUTION
Avatar of Kiran Paul VJ
Kiran Paul VJ
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial