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 $something@blah.com

 

How would I name a variable so I can have a variable inside a variable and will work?  When I tried this, $to@somesite.com, 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
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
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 = 'youremail@gmail.com';
  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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.