Jump to content

How do you..


firecat318

Recommended Posts

Alright, say I wanted somebody to be able to send an email, but it would be [email protected]

 

How would I name a variable so I can have a variable inside a variable and will work?  When I tried this, [email protected], I got a php error.  I assume you need to form it in a special way so you don't get an error?

 

Remember, $to is an input field which they fill in.

Link to comment
https://forums.phpfreaks.com/topic/103809-how-do-you/
Share on other sites

<form action=" <?php $_SERVER['PHP_SELF']; ?> " method="POST">

To:

<input type="text" name="to" size="30" /><br />

From:

<input type="text" name="from" size="30"><br />

Message: <input type="text" name="message" size="70" /><br />

<input type="submit" name="submit" value="submit">

</form>

 

<?php

$message = $_POST['message'];

$too = $_POST['from'];

$email = $too.'@gmail.com';

 

mail($email, $message);

 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/103809-how-do-you/#findComment-531462
Share on other sites

first, the syntax is:

mail  ( string $to  , string $subject  , string $message )

so it should look more like:

<?php
  $message = $_POST['message'];
  $to = $_POST['from']; //Removed the extra o 
  $email = $to.'@gmail.com';
  mail($email, 'This is the subject', $message);
?>

 

there is nothing wrong with the code above though. you can always try hard coding it first to test:

<?php
  $message = 'This is a sample message';
  $email = '[email protected]';
  mail($email, 'This is the subject', $message);
?>

if you don't get that email, then contact your hosting service. if it's your server, then you probably don't have mail setup properly

Link to comment
https://forums.phpfreaks.com/topic/103809-how-do-you/#findComment-531526
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.