pjmil
pjmil

Reputation: 2097

PHP open new email message with default mail client

I want to open an email from a link that is the persons email address, which is displayed in a table with their personal information.

I can 'kind of' get it to work doing this;

<a href="mailto:<?php $person['Person']['primEmail']; ?>"><?php echo $person['Person']['primEmail']; ?></a>

The new email opens using the default mail client, however the email address is not populated in the 'To:' field, which is really what I am after.

Upvotes: 4

Views: 12043

Answers (3)

MasterT
MasterT

Reputation: 623

Try this

<?php

    header("location: mailto:".$person['Person']['primEmail']);

?>

it works for me

Upvotes: 1

Ganesh Bora
Ganesh Bora

Reputation: 1153

YOur code is write...reason for not populating To address is that there is minor issue in your code.. there is no echo in anchor tag...

<a href="mailto:<?php echo $person['Person']['primEmail']; ?>"><?php echo $person['Person']['primEmail']; ?></a>

Upvotes: 0

user113292
user113292

Reputation:

The code you have produces the following:

<a href="mailto:">[email protected]</a>

Which causes the behavior you're experiencing because the href attribute isn't pointing to an actual email address. This is due to the missing print or echo in the href attribute. Your code should look like this, instead:

<a href="mailto:<?php echo $person['Person']['primEmail']; ?>"><?php echo $person['Person']['primEmail']; ?></a>

Which will produce:

<a href="mailto:[email protected]">[email protected]</a>

And will work as intended.

Upvotes: 8

Related Questions