• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

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
0
Jason
Asked:
Jason
  • 2
  • 2
1 Solution
 
Kiran Paul VJComputer EngineerCommented:
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");?>
0
 
vnsmanian2006Commented:

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>
0
 
JasonAuthor Commented:
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
0
 
JasonAuthor Commented:
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";
?>       
0
 
Kiran Paul VJComputer EngineerCommented:
ok try this, only one page

page1.php

<?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";

if(isset($_GET['sendemail']) && $_GET['sendemail']=="1")
{
   mail(MAIL_ADDRESS, MAIL_SUBJECT, $content, $headers);
}
?>  
<html>

<head>
<script language="javascript">
function SendMail()
{
  window.location.href='page1.php?sendemail=1';
}
</script>
</head>

<body>
<a href="" onclick="Send Mail();" >Email</a>
</body>

</html>

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now