Hi, i wonder if someone can help me. I've been surfing Google trying to find a solution but no luck...

i want to create a mailto link on an image, but when the email opens, it should have preset text...is this something that i would have to set up so it pulls from a database, because i can't seem to let it allow me to add it in with code on my page.

Much appreciated. thanks

Dani AI

Generated

Nice work, — and good-natured reply from . A few extra tips and small refinements that help when using mailto links on images or when you need prefilled, DB-driven text.

Keep the image clickable by wrapping it with the anchor. Percent-encode the subject/body and use CRLF for line breaks (%0D%0A). When the URI is placed directly in HTML, escape ampersands as & so the markup stays valid:

<a href="mailto:someone@example.com?subject=Website%20question&amp;body=Hi%20there%2C%0D%0A%0D%0AI%27m%20interested%20in...">
  <img src="/images/email-icon.png" alt="Email us">
</a>

If the prefilled text comes from a database, build the mailto string on the server or in JavaScript and run it through encodeURIComponent to avoid broken characters and injection issues. Example JS pattern:

const subject = encodeURIComponent(dbSubject);
const body = encodeURIComponent(dbBody);
linkElement.href = `mailto:${address}?subject=${subject}&body=${body}`;

Caveats to keep in mind: attachments cannot be added via mailto; some webmail setups or browsers may not open a handler the way you expect; very long bodies can be truncated by clients; plain email addresses in markup are easy for harvesters to scrape. For reliable behavior or to keep addresses private, use a server-side contact form that sends mail from your server.

For exact mailto-URI rules and required percent-encoding, see the standards (RFC 6068) for reference: RFC 6068.

problem solved!!

here it is if there is someone just as silly as me..haha

<a href="mailto:?subject=test&body=body copy to be added" >EMAIL ME</a>

Member Avatar for Member #360561

problem solved!!

Once upon a time I didn't know either!
Nothing to be ashamed of! :)

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.